cross platform file lock

Ype Kingma ykingma at accessforall.nl
Wed Jan 17 11:05:12 EST 2001


Godefroid,

gotcha at swing.be wrote:
> 
> This is a newbie question...
> 
> But after browsing Python Library reference,
> Python FAQ, and comp.lang.python, I have not been
> able to determine if there is a cross platform
> file locking mechanism available for Python.
> 
> any help appreciated

It isn't there. In case you need to do interprocess
communication you can do it with files, eg. by
using two files:

Program A writes file1, and deletes file2.
Program B waits for deletion of file2 and then reads file1.
Program B writes it's answer in file2 and then deletes file1.
Program A meanwhile waits for deletion of file1 and the it
           reads file2.
Etc. etc.

This works. However, it is _slow_.

You are better off with sockets for IPC, these are also
more flexible.
I just made sth. that uses sockets and works in Jython,
it mike work in CPython also.

I have example python code for sockets, just ask.

In case you need still faster IPC you'll probably be
tied to sth platform specific, eg. memory mapped files
in Unix.
In my case sockets are good enough, even from Jython.

Regards,
Ype

-- 
email at xs4all.nl



More information about the Python-list mailing list