file locking

Steve Holden sholden at holdenweb.com
Tue Mar 27 08:53:45 EST 2001


"Alex Martelli" <aleaxit at yahoo.com> wrote in message
news:99n47u02fk at news2.newsguy.com...
> "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.
>
Perhaps another place where the platform-specific libraries need a common
shim layer over them to give a portable API. Does the Mac have any quirks in
this area?

regards
 Steve






More information about the Python-list mailing list