Python-queue Knowledge points

Source: Internet
Author: User

1.dict Get Value
Dict.get (Key_name)
2. Ternary operation

Res,err=stdout.read (), Stderr.read () #三元运算
Result=res If res else err
Print (Result.decode ())
36:10


Knowledge Review:
1. Executing a thread, how do I get the results?
2.event
Event.set () #green_light =ture
Event.wait () #等待set方法执行
Event.clear () #green_light =false
3.assert Assertion


Problem:

1.python the difference between a process and a thread

2.GIL effect: Prevents the underlying native C program from modifying the same data at the same time (GIL denotes global interpreter lock)
3.setdaemon

Queue class:


Lifo:last in First Out
Queue. The Lifoqueue (maxsize=0) maxsize parameter is used to set the maximum upper value, maxsize<=0 represents the Infinity
Fifo:first in First Out
Queue. The Queue (maxsize=0) maxsize parameter is used to set the maximum upper value, maxsize<=0 represents infinity


Queue. Priorityqueue (maxsize=0) Priority Queue Construction method
The lowest valued entries is retrieved first (the lowest valued entry was the one returned by sorted (list (entries)) [0]). A typical pattern for entries are a tuple in the form: (Priority_number, data).

Queue. Empty: Used to determine if the object in the queue is empty, and if it is empty, calling the Get or get_nowait () method throws an exception.

Queue. Full: Used to determine if the object in the queue is fully filled, and the call to put or the put_nowait () method throws an exception.


Queue Object method
Queue.qsize (): Returns the approximate size of the queue, Qsize>0 does not guarantee that subsequent get () will not block, and Qsize<maxsize does not guarantee that subsequent put () will not block.

Queue.empty (): The queue is empty and returns true, otherwise false is returned. If true, no subsequent get () is guaranteed to be blocked. Similarly, if False is returned, no subsequent put () is guaranteed to be blocked.

Queue.full (): Queue is full, returns True, otherwise false. If true, no subsequent get () is guaranteed to be blocked. Similarly, if False is returned, it does not ensure that the put () is not blocked.

Queue.put (Item,block=true,timeout=none): Pass in a value to the queue, if block is True, block if necessary until an idle slot is available in the queue. Timeout is used to set the time-out.

Queue.put_nowait (item): Equivalent to put (Item,false)

Queue.get (Block=true,timeout=none): Remove from queue and return an item

Queue.get_nowait (): Equivalent to get (False)

Support for tracking daemon threads to fully handle queued tasks:
Queue.task_done ()
Queue.join ()

Python-queue Knowledge points

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.