Question

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

Was it helpful?

Solution

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 :))

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top