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

Carl J. Van Arsdall cvanarsdall at mvista.com
Mon Jul 17 18:11:09 EDT 2006


pavlovevidence at gmail.com wrote:
>
>> ith a quick look.
>>     
>
>
> f = open("/path/to/data/directory/lockfile","r")
> try:
>     fcntl.flock(f.fileno(),fcntl.LOCK_EX)
>     ...access data freely here...
> finally:
>     f.close()
>
> Closing the file should release the lock (unless you have a truly
> horrible operating system).
>
>   
I also find that fcntl has problems with NFS (or at least, *I* had 
problems using the python fcntl module and nfs - could be that horrible 
operating system, but doing things like that over nfs can be tricky).


-carl

-- 

Carl J. Van Arsdall
cvanarsdall at mvista.com
Build and Release
MontaVista Software




More information about the Python-list mailing list