[Python-Dev] PEP 3147, __pycache__ directories and umask

Cameron Simpson cs at zip.com.au
Tue Mar 23 01:45:19 CET 2010

On 23Mar2010 11:40, I wrote:
| | * Raise an exception or refuse to create __pycache__ if it's not writable
| |   (again, by whom?)
| -3
| Bleah. My python program won't run because an obscure (to the user)
| directory had unusual permissions?

Clarification: I'm -3 on the exception. Silent failure to make the
__pycache__ would do, and may be better than silently making a useless
(unwritable) one.  

How about:

  made_it = False
  ok = False
    if not isdir(__pycache__dir):
      made_it = True
    write pyc content ...
    ok = True
  except OSError, IOerror etc:
    if not ok:
      os.remove pyc content file
      if made_it:
        rmdir(__pycache__dir) but be quiet if this fails,
          eg if it is not empty because another process or thread
             added stuff

So silent tidyup attempt on failure, but no escaping exception.

Cameron Simpson <cs at zip.com.au> DoD#743

The govt MUST regulate the Net NOW! We can't have average people saying
what's on their minds!  - ezwriter at netcom.com

More information about the Python-Dev mailing list