Python concurrent Programming: Multi-process-queue

Source: Internet
Author: User

Queue description

  Processes are isolated from each other, and to implement interprocess communication (IPC), the Multiprocessing module supports two forms: queues and pipelines, both of which use message passing

Create a queue class (the underlying is implemented as a pipe and lock)

Queue (MAXSIZE): Creates a shared process queue, which is a multi-process secure queue that enables data transfer between multiple processes using queue

  Parameter introduction

MaxSize is the maximum number of items allowed in the queue, omitted without a size limit but needs to be clear:    1, the queue is stored in the message rather than the big Data    2, the queue occupies the memory space, so maxsize even if no size limit is limited by the memory size

Introduction to the main methods

The Q.put method is used to insert data into the queue Q.get method can read from the queue and delete an element

Use of queues

From multiprocessing Import Queueq = Queue (3) q.put (1) q.put (2) q.put (3) print (Q.full ())     # full # q.put (4)  # It's jammed again. Print (Q.get ()) print (Q.get ()) print (Q.get ()) print (Q.empty ())    # Empty print (Q.get ())  # and then it's jammed.

  

Python concurrent Programming: Multi-process-queue

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.