[Tilecache] make dir error

Christopher Schmidt crschmidt at metacarta.com
Thu Apr 10 10:58:33 EDT 2008


On Thu, Apr 10, 2008 at 04:52:00PM +0200, Fredrik Lundh wrote:
> >  i just tried myself having a look into the source code, but i am a totally rookie in python. surrounding the self.makedirs() statement with a try: / finally: did not do the job and resulted in another error.
> 
> you want
> 
>     try:
>          ...
>     except OSError:
>          pass
> 
> instead of try-finally (the latter catches exceptions and reraises them).
> 
> the real reason for this is that os.makedirs isn't quite robust enough
> for parallel use; it does catch "already exists" errors (errno 17) for
> intermediate directory levels, but not for the final node.  to fix
> this, TileCache could do something like:
> 
>     import errno, os
> 
>     def safe_mkdir(path):
>         if os.path.isdir(path):
>             return
>         try:
>             os.makedirs(path)
>         except OSError, e:
>             if e.errno != errno.EEXIST:
>                 raise
> 
> and then use safe_mkdir instead of any isdir/makedirs combo.

Agreed. I keep thinking I've already done this, but never get around to
it. I'll take a patch... 

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Tilecache mailing list