0

I run a python 2.7 program with tensorflow on my ubuntu 16.04 machine. At some point (it randomly changes when that happens), the program crashes because os.getcwdu() fails. I then run python in the same terminal session, try to run import os followed by os.getcwd() and get the same error:

OSError: [Errno 2] No such file or directory

only after exiting python (again), going up one directory and re-entering that directory I am able to run this command.

Does anyone have any idea what causes this problem and how to avoid it? Many thanks in advance!

  • 1
    Does your program do any other file/OS manipulation? I suspect you may be calling `os.getcwd()` on a stale file handle. – Salvatore Apr 04 '19 at 22:57
  • I do create files and folders. How would I debug this? Note, that in contrast to this guy https://stackoverflow.com/questions/6195301/os-getcwd-throws-exception , I can execute ls in the command line and get the same results as before starting the programs. – FightGravity Apr 05 '19 at 10:09
  • PS: I just realised that the fact that I am doing all this in a tmux session might be relevant! – FightGravity Apr 05 '19 at 14:38

1 Answers1

2

If you are getting an OSError[errno 2] for os.getcwd() , then the current working directory has been deleted. It is possible that some other process has created a new directory with the same name. That is why you can change directories back into your folder.

  • Thank you for your response! However, I can not imagine that this directory is being deleted at any point. Moreover, there are multiple files (run scripts) in this directory, which are still there after it breaks. So any process which deletes and then re-creates the directory would have to put the files back in. Maybe something is moved back and forth rather than deleted? Is there, e.g, any internal Ubuntu process which would explain such behaviour? – FightGravity Apr 05 '19 at 09:56
  • A move would not cause an OSError [errno 2] – Everett Rush Apr 05 '19 at 14:30