Difference between mutex.mutex and threading.Lock

S

sven

Hi,

what is the difference between mutex.mutex and threading.Lock?
Neither the documentation nor a Google search gave me any clue.

Another issue: The documentation of mutex in version 2.6.4 says:

"Deprecated since version The: mutex module has been removed in Python
3.0."

Maybe it should also say what to use instead (probably
threading.Lock?). Also the "version The" part seems a bit strange.

Greetings,
Sven
 
Z

zeph

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
 
R

Roy Smith

zeph said:
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."

Over the years, many things about Python have surprised, amused, and on
occasion confused, me. I must admit, having a mutex which isn't
thread-safe is pretty high up on the list of "does not fit my brain" items
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top