class mutex

Michel Pelletier michel at digicool.com
Sun Oct 22 05:22:34 EDT 2000


"Prof. Peter Stoehr" wrote:
> 
> Hi out there,
> 
> there is a class mutex shipped with python. I've tried to use it to
> syncronise two processes created with os.fork() and failed :-(
> Looking at the source code of mutex.py I found out, that it is
> implemented in pure python. Thus, it does not implement a real
> mutex-object as a python code can be interrupted after each step of the
> byte-code.
> Based on that, I have two questions:
> 1) Does python provide a real mutex object.
> 2) What is the use of the class mutex

I do not know the answer to your questions and my suggestion may not be
anything what you are looking for, but Zope comes with an ExtensionClass
C extension module which has a Synchronized base class which you can use
to ensure that only one thread of execution can execute a method of a
class at any time.

Also, doesn't fork create a new process?  I wouldn't think any mutex
would hold across process boundaries, only thread boundaries.

Good luck,

-Michel



More information about the Python-list mailing list