data structure-- first-in first-out (fifolist of python objectsin which items are added on one end and removed from the other like normal liststhe queues provided by this module may contain any type of python objectincluding both simple types (stringslistsdictionariesand so onand more exotic types (class instancesarbitrary callables like functions and bound methodsand moreunlike normal liststhoughthe queue object is automatically controlled with thread lock acquire and release operationssuch that only one thread can modify the queue at any given point in time because of thisprograms that use queue for their crossthread communication will be thread-safe and can usually avoid dealing with locks of their own for data passed between threads like the other tools in python' threading arsenalqueues are surprisingly simple to use the script in example - for instancespawns two consumer threads that watch for data to appear on the shared queue and four producer threads that place data on the queue periodically after sleep interval (each of their sleep durations differs to simulate reallong-running taskin other wordsthis program runs threads (including the main one) of which access the shared queue in parallel example - pp \system\threads\queuetest py "producer and consumer threads communicating with shared queuenumconsumers numproducers nummessages how many consumers to start how many producers to start messages per producer to put import _thread as threadqueuetime safeprint thread allocate_lock(else prints may overlap dataqueue queue queue(shared globalinfinite size def producer(idnum)for msgnum in range(nummessages)time sleep(idnumdataqueue put('[producer id=%dcount=% ](idnummsgnum)def consumer(idnum)while truetime sleep( trydata dataqueue get(block=falseexcept queue emptypass elsewith safeprintprint('consumer'idnum'got =>'dataif __name__ ='__main__'for in range(numconsumers)thread start_new_thread(consumer( ,)for in range(numproducers)threads