Difference between mutex.mutex and threading.Lock

zeph zephjc at gmail.com
Fri Dec 4 17:22:28 EST 2009


The mutex class (and module) should not be used, since it is, as you
said, deprecated for 3.0. Like the docs say, it "does not require (or
imply) threading or multi-tasking, though it could be useful for those
purposes."  The mutex class' lock() method takes a function and args
and if the mutex is unlocked, calls the function with args
immediately, or if locked, adds to a queue and waits for it to be
unlocked

The threading.Lock object is a lock shared between threads.  For
example, if you have two threads (thread1 and thread2) and thread1
does lock.acquire() and thread 2 calls lock.acquire(), thread2 will
block until thread1 calls lock.release(), then thread2 will get a
chance to run its critical code section, then call lock.release().

- zeph



More information about the Python-list mailing list