Python Thread queues---queue

Source: Internet
Author: User

Queue queues: Use import queue, same usage as process queue

Usage Description:

queue. class Queue (maxsize=0) #先进先出
ImportQueueq=queue. Queue () Q.put (' First') Q.put ('Second') Q.put ('Third')Print(Q.get ())Print(Q.get ())Print(Q.get ())" "result (FIFO): Firstsecondthird" "

queue. class LifoQueue (maxsize=0) #后进的先出

ImportQueueq=queue. Lifoqueue () Q.put (' First') Q.put ('Second') Q.put ('Third')Print(Q.get ())Print(Q.get ())Print(Q.get ())" "result (last in first out): Thirdsecondfirst" "

queue. class PriorityQueue (maxsize=0) #存储数据时可设置优先级的队列

ImportQueueq=queue. Priorityqueue ()#put into a tuple, the first element of a tuple is a priority (usually a number, or a comparison between non-numbers), and the smaller the number the higher the priorityQ.put (20,'a')) Q.put (10,'b')) Q.put (30,'C'))Print(Q.get ())Print(Q.get ())Print(Q.get ())" "results (The smaller the number, the higher the priority, the higher the priority queue):(, ' B ') (The ' a ') (+, ' C ')" "

Python Thread queues---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.