title: os.getcwd() throws Exception
body: <p>I have situation when the current directory becomes invalid (ie, when some program deletes it). My Python script calls <code>os.getcwd()</code> which terminates with following exception</p>
  
  <p><code>OSError: [Errno 2] No such file or directory</code></p>
  
  <p>Ideally, it my script would automatically cd into parent directory in such situation.
  When is the recommended strategy for implementing this?</p>
  
  <p>Note, if I try <code>ls</code> from the shell, I get <code>ls: cannot open directory .: Stale NFS file handle</code></p>