Chapter 3 Multiprocessing Flashcards
Process
Process API takes a function to execute and runs it in a new process.
Process(target=process_task, name=”process-{0}”.format(i))
Fork
Process can be created by fork, spawn and forkserver. This is set in the library using multiprocessing.set_start_method(‘fork’)
Fork disadvantages
For copies almost everything from the current process, this could be problem with lock states, open file descriptors etc
Spawn
Spawn uses exec to replace the state. Spawn is set using multiprocessing.set_start_method(‘spawn’)
Forkserver
Need to study
Queues and pipes
Queues take items, pipes are like files.
Shared memory
created using Value
Locks and reentrant locks
as usual
Barrier, semaphore and condition variable
same as threads
Pool
Creates a pool of processes which execute multiple tasks and do not die immediately
Maps
map api are available to distribute work to a pool
Managers
Managers are a way to share data and co-ordinate between processes running on different machines.
Creating Manager
BaseManager creates a manager and binds it to a port. To connect, we create a BaseManager and call connect. Then we can call the api to get work.
Types of Managers
- BaseManager
2. CustomManager, subclassing from BaseManager
SyncManager
SyncManager synchronizes between server and client.