The Queue object

Python's queue.Queue is a first-in first-out (FIFO) data structure. Items can be placed into a Queue object using the put() method, and retrieved using the get() method. Let's take a look at the following example:

>>> from queue import Queue
>>> q = Queue()
>>> q.put('My item')
>>> q.get()
'My item'

This may not seem terribly exciting, but what makes Queue useful is that it has been specially designed to work safely as a channel for asynchronous communication between threads (programmers refer to this as thread-safe). One thread can place messages on queue, and another can retrieve them and respond appropriately.

By default, get() will block until an item is received. This behavior can be altered by passing False as its first ...

Get Python GUI Programming with Tkinter now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.