I have situation when the current directory becomes invalid (ie, when some program deletes it). My Python script calls os.getcwd() which terminates with following exception
OSError: [Errno 2] No such file or directory
Ideally, it my script would automatically cd into parent directory in such situation.
When is the recommended strategy for implementing this?
Note, if I try ls from the shell, I get ls: cannot open directory .: Stale NFS file handle
Just use
try/exceptblock for that, that’s what for we have them 🙂or something similar…
[edit] Anyway I guess such situation is realy bad for your app – deleted dir, or broken NFS connection etc, and this probably should not be silienced by just change dir – it depends on app of course…