If the value of maxsize will be less than or equal to zero then the size of the queue will be infinite. Insertion operation will be blocked once this size has been reached, until the queue elements are consumed. Argument maxsize is an integer which sets the upper bound limit on the number of elements that can be placed in the queue. Classes and exceptions in the queue module is as follows: class queue.Queue(maxsize = 0) And for priority queue, elements are kept in sorted order (using the heapq module) and the lowest valued element will be removed first. For the FIFO queue, the first element added is the first element removed and for the LIFO queue(it works like a stack), the most recent element added will be the first element which will be removed. The queue module has three types of queue implementation, which differ only in the order in which the entries are retrieved. The Queue class in this module implements all the required locking semantics and it depends on the thread support’s availability in Python. The queue module is used to implement multi-producer, multi-consumer queues and it is very useful in threaded programming when we have to exchange the information safely between multiple threads. In Python, there are inbuilt functions and classes which will make our code shorter and simple. element which is inserted first will be removed first. And queue works on the principle of FIFO (First in First out) i.e. element which is inserted in last will be removed first. Stack works on the principle of LIFO (Last in First out) i.e. In python, it is quite easy to implement stack and queue data structures.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |