SyncManager
Explore how to use Python's SyncManager class to create synchronization proxies like semaphores and shared lists for coordinating multiple processes. Understand inter-process communication, synchronization mechanisms, and how changes to shared objects propagate between processes. This lesson covers practical examples applying SyncManager to solve real concurrency coordination challenges.
We'll cover the following...
Sync Manager
So far we have been using time.sleep() to delay the server manager from shutting down before other processes had a chance to retrieve shared objects from it. Obviously, this isn't a good strategy and we need a better way to coordinate among the different processes. Fortunately, there's a subclass of BaseManager called the SyncManager which offers proxies of synchronization constructs from the threading module. Let's revisit the example we discussed under the manager section where we used a timer to delay shutting down the manager. We'll replace the base manager with a sync manager and create a semaphore proxy using the sync manager. The main process would wait on the semaphore while the child process after accessing the shared objects would set the semaphore. The code appears below:
SyncManager implements tools for ...