Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

portalocker 1.0b - Simple cross-platform (nt/posix) advisory file locking

0 views
Skip to first unread message

Jonathan Feinberg

unread,
May 29, 2001, 3:08:24 PM5/29/01
to

Please, experienced Pythonistas: examine, critique, patch, and extend
to other platforms. I am fairly new to Python, so my method of
platform-specific code segregation might strike you as inelegant or
worse. I welcome all constructive comments.

http://www.panix.com/~jdf/python/portalocker.py

Cross-platform (posix/nt) API for flock-style file locking.

Synopsis:

import portalocker
file = open("somefile", "r+")
portalocker.lock(file, portalocker.LOCK_EX)
file.seek(12)
file.write("foo")
file.close()

If you know what you're doing, you may choose to

portalocker.unlock(file)

before closing the file, but why?

Methods:

lock( file, flags )
unlock( file )

Constants:

LOCK_EX
LOCK_SH
LOCK_NB

I learned the win32 technique for locking files from sample code
provided by John Nielsen <niel...@my-deja.com> in the documentation
that accompanies the win32 modules.

--
Jonathan Feinberg j...@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf

0 new messages