Yesterday's content review
Queue queue: FIFO, data process secure Queue implementation: Pipeline + lock producer Consumer Model: Resolve data supply and demand unbalanced pipeline bidirectional communication, data process insecure Eoferror: Pipeline is a reference count by the operating system must be closed in all processes before you can generate Eoferror exception data sharing (infrequently used) Manager list dict data process unsafe process pool storage container for process at the beginning of the process creation, creating a fixed number of processes will be recycled by multiple tasks saving process creation and destruction time overhead reduces the amount of pressure and process pool differences in the operating system scheduling process semaphore: N Tasks Open N processes , But there can only be a fixed number of processes at the same time in the execution process waiting to be executed process pool: N tasks to open a fixed number of processes so only a fixed number of processes in the execution of the task is waiting to be executed
The queue is a built-in lock, so it is safe for other applications to call it.
When it comes to manual locking, it is unsafe. Commonly used is the message middleware
Galena with no return value
Close and join paired use
Import timefrom multiprocessing Import pooldef Wahaha (i): time.sleep (1) print (' * ' * i) if __name__ = = ' __main__ ': p = Pool (5) # The recommended number is CPU cores +1 for I in range (5): P.apply_async (Func=wahaha, args= (i,)) P.close () # No more new tasks to submit P.join () # Wait for the tasks in the pool to finish executing
Execution output:
Python full stack development, Day41 (threading concept, threading features, process and thread relationships, threading and Python theory knowledge, threading creation)