Reputation: 2084
Maybe I didn't read the docs that well, but I didn't find more information about how lock's or rlock's aquire work ... does it block all processes no matter what statements those processes are on (even if they are on no critical sections).. or does it block only the processes trying to access the critical section
Thank you !
Upvotes: 0
Views: 43
Reputation: 4461
From the docs:
class
multiprocessing.Lock
A non-recursive lock object: a close analog of threading.Lock. Once a process or thread has acquired a lock, subsequent attempts to acquire it from any process or thread will block until it is released; any process or thread may release it. The concepts and behaviors of threading.Lock as it applies to threads are replicated here in multiprocessing.Lock as it applies to either processes or threads, except as noted.
So when you call acquire()
(note the use of default value for the block
parameter) your process will:
This mechanism allows you to define "critical sections" in your logic, meaning that only one process at a time will be executing that particular function (i.e. playing an audio file)
Upvotes: 2