[Tutor] File locking

Smith, Jeff jsmith at medplus.com
Mon Mar 12 19:04:51 CET 2007


I'm always disappointed when I find something that Python doesn't handle
in a platform independent way.  It seems to me that file locking is in
that boat.
 
1. I don't see a way to atomically open a file for writing if and only
if it doesn't exist without resorting to os.open and specialized
platform O_XXX flags.
 
2. I don't see a way to atomically open a file for writing and obtain a
lock on the file.
 
3. I don't see a platform independent way to obtain a lock on a file.
You have to do something goofy like
if sys.platform == win32:
    import msvcrt
else:
    import fcntl
and then similar things to call the correct functions with the correct
flags.
 
Please let me know if I'm missing something since they seem like normal
file operations that I would hope Python would abstract away.  If not,
are there any PEPs concerning this for Python3K?
 
Thanks,
Jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070312/8726f726/attachment.html 


More information about the Tutor mailing list