How to synchronize processes
Multiple processes can work together to perform a given task. Usually, they share data. It is important that the access to shared data by various processes does not produce inconsistent data. Processes that cooperate by sharing data must therefore act in an orderly manner in order to access that data. Synchronization primitives are quite similar to those encountered for the library and threading.
They are as follows:
- Lock: This object can be in one of the states: locked and unlocked. A lock object has two methods,
acquire()
andrelease()
, to manage the access to a shared resource. - Event: This realizes simple communication between processes, one process signals an event and the other processes wait for it. An
Event
object ...
Get Python Parallel Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.