Posts

Showing posts with the label Python

A Quick Guide of Multithreading with Queue in Python

Image
As described in the beginning of [1]: "The Queue module implements multi-producer, multi-consumer queues. It is especially useful in threaded programming when information must be exchanged safely between multiple threads. The Queue class in this module implements all the required locking semantics." Therefore the implementation of multi-threading with Queue is quite handy and approachable to beginners in my opinion. I strongly recommend the references [2][3] for some head-first understandings on this topic. Note that after python 2.4, it is in general recommended the  threading  module for multi-thread programming instead of the  thread  module in previous version. Don't get confused when you're crawling the web for information. Also note there's a well known Global Interpreter Lock (GIL) issue in CPython [4]. We'll discuss this later. Multi-threading with Queue in Python 1. Producer-Consumer Model Say you want to parallelize a piece of code with m...