Python full stack development, DAY40 (interprocess communication (queue and pipeline), inter-process data sharing manager, Process Pool)

Source: Internet
Author: User
Tags semaphore

Yesterday's content review
Process multiprocessprocess--process creates a module of a process in Python the    start    daemon daemon    join waits for the child process to execute the end lock Lockacquire Release Lock is a tool for synchronous control if there are multiple processes executing a piece of code at the same time, then the data in memory will not conflict, but if the file is involved, There is a resource conflict problem with the database. We need to lock this code up with a lock. After any process executes the acquire, all other processes will block here, waiting for a release semaphore Semaphore lock + Counters can only have a specified number of processes executing the same piece of code event at the same time Eventset clear Is_set   control the state of the object wait  depending on the state to perform the effect also different    state is true---> Pass    The status is false--blocking general wait is and set clear is placed in a different process set/clear is responsible for controlling the state wait is responsible for perceiving state I can control the operation of another or more processes in one process IPC communication queues queue Pipeline pipe
I. interprocess communication (Queues and pipelines)

Determine if the queue is empty

From multiprocessing Import Process,queueq = Queue () print (Q.empty ())

Execution output: True

Determine if the queue is full 

From multiprocessing Import Process,queueq = Queue () print (Q.full ())

Execution output: False

If the queue is full, then the operation to increment the value will be blocked until the queue has a spare

From multiprocessing import Process,queueq = Queue   # Create a queue that can only put 10 value for I in range:    q.put (i)    # Add a Valueprint (Q.qsize ())    # Returns the correct number of current items in the queue print (Q.full ())     # If q is full, return to Trueq.put (111)  # and add another value print ( Q.empty ())

Execution output:

You can see that the program is not over, and the code after Q.put (111) is blocked.

Summarize:

Queues can specify a capacity at the time of creation

If the queue already has enough data in the process of running the program, then put will block

If the queue is empty, then get is blocked

Why do you want to specify the length of the queue? is to prevent memory explosion.

A queue that cannot be stored indefinitely. After all, there is a limit to memory.

The put, get, qsize, full and empty mentioned above are not allowed.

Items may be added or deleted in the queue because of the results returned and the results are used later in the program. On some systems, this method may throw an Notimplementederror exception.

If other processes or threads are adding items to the queue, the results are unreliable. In other words, the results are returned and used

Python full stack development, DAY40 (interprocess communication (queue and pipeline), inter-process data sharing manager, Process Pool)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.