Get The Most Affordable Hosting in the World!
Starting at just $1.87/month, Vercaa offers unbeatable pricing for world-class web hosting services.
Fast, reliable, and secure hosting to power your website without breaking the bank. Plus, enjoy a free CDN for faster loading times worldwide!
Get Started Now!The queue module in Python's standard library is useful in threaded programming when information must be exchanged safely between multiple threads. The Priority Queue class in this module implements all the required locking semantics.
With a priority queue, the entries are kept sorted (using the heapq module) and the lowest valued entry is retrieved first.
The Queue objects have following methods to control the Queue −
-
get() − The get() removes and returns an item from the queue.
-
put() − The put adds item to a queue.
-
qsize() − The qsize() returns the number of items that are currently in the queue.
-
empty() − The empty( ) returns True if queue is empty; otherwise, False.
-
full() − the full() returns True if queue is full; otherwise, False.
This is the Constructor for a priority queue. maxsize is an integer that sets the upper limit on the number of items that can be placed in the queue. If maxsize is less than or equal to zero, the queue size is infinite.
The lowest valued entries are retrieved first (the lowest valued entry is the one that would be returned by min(entries)). A typical pattern for entries is a tuple in the form −
Example
It will produce the following output −
Producer: Running Consumer: Running (0, 0.15332707626852804) (2, 0.4730737391435892) (2, 0.8679231358257962) (3, 0.051924220435665025) (4, 0.23945882716108446) Producer: Done Consumer: Done
The End! should you have any inquiries, we encourage you to reach out to the Vercaa Support Center without hesitation.