Using queues

In most cases, it is safer and simpler to use queues. Simply put, a queue is a compound memory structure that is thread-safe. Queues effectively channel access to a resource to multiple threads in a sequential order, and are a recommended design pattern that uses threads for most of the scenarios that require concurrency.

The Queue module provides a way to implement different kinds of queuing, such as FIFO (default implementation), LIFO queues, and priority queues, and this module comes with a built-in implementation of all the locking semantics required for running multithreaded programs.

Here's a quick roundup of the basic usage of the Queue module:

my_queue = Queue() #create empty queuemy_queue.put(data)# put items into queue ...

Get Tkinter GUI Application Development Blueprints - Second Edition 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.