Locking blockl to a people on a similar group / naming locks
Paul Rubin
http
Wed Jan 21 04:09:48 EST 2009
reyjexter <reyjexter at gmail.com> writes:
> synchronize (myGroup) {
> }
>
> but how do I do this in python? how can I name the lock that will be
> used by the thread?
You have to do it explicitly, for example with RLock:
myInstance.lock = RLock()
...
myInstance.lock.acquire()
... critical section ...
myInstance.lock.release()
It's often possible to write in a style that avoids this mess.
The preferred way is usually to write isolated threads that
communicate by passing objects through queues (Queue.Queue).
This gets rid of a lot of locking hazards.
More information about the Python-list
mailing list