How to lock files (the easiest/best way)?

Eric S. Johansson esj at harvee.org
Sun Jul 16 16:28:08 EDT 2006


Elmo Mäntynen wrote:
> Is there something better than using fnctl? It seems a bit intimidating
> with a quick look.

try the portlocker wrapper from the active state cookbook.  I have a 
version which has been slightly updated for more modern pythons.  I 
really need to make my darcs repository visible so you could get it.

Alternatively, you can try the makedir trick.  Creating directories are 
atomic operations if it exists, you will get error message.  If it 
doesn't, you will get a directory and thereby capture the lock.  You 
delete the directory when you release the lock.

crude but effective.  I used it in building a file based queue system. 
You know, I really should learn how to build eggs because I have a whole 
bunch of little pieces of software that would probably be useful to others.

---eric




More information about the Python-list mailing list