file locking

Alex Martelli aleaxit at yahoo.com
Mon Mar 26 05:04:45 EST 2001


"Steve Purcell" <stephen_purcell at yahoo.com> wrote in message
news:mailman.985596999.26319.python-list at python.org...
> deadmeat wrote:
> > How do I lock a file on opening it?  the bultin open() only allows me to
set
> > the read/write mode, not any deny modes.
>
> On Unix, look at the 'flock' function in the module 'fcntl'.
>
> You can also try the 'posixfile' module -- posixfile objects support
locking.

On Win32, look at module win32file; its CreateFile function has
a shareMode parameter.  Getting a Python fileobject from the
HANDLE returned by CreateFile is a tad tedious -- I _think_ you
have to use win32file._open_osfhandle to get an (integer) C
level handle from the opaque HANDLE, then os.fdopen to get from
said int-handle to a Python fileobject.


Alex






More information about the Python-list mailing list