views:

565

answers:

3

Are the locks from the threading module interchangeable with those from the multiprocessing module?

+1  A: 

I don't think so. Threading locks are within the same process, while the multiprocessing lock would likely be in shared memory.

Last time I checked, multiprocessing doesn't allow you to share the lock in a Queue, which is a threading lock.

Unknown
A: 

Yes, you can use locks from the multiprocessing module as normal in your one-process application, but if you're using multiprocessing, you should use its locks.

sysrqb
+3  A: 

You can typically use the two interchangeably, but you need to cognizant of the differences. For example, multiprocessing.Event is backed by a named semaphore, which is sensitive to the platform under the application.

Multiprocessing.Lock is backed by Multiprocessing.SemLock - so it needs named semaphores. In essence, you can use them interchangeably, but using multiprocessing's locks introduces some platform requirements on the application (namely, it doesn't run on BSD :))

jnoller