threads and concurrency setprofile(funcsets profile function that will be used for all threads created func is passed to sys setprofile(before each thread starts running settrace(funcsets tracing function that will be used for all threads created func is passed to sys settrace(before each thread starts running stack_size([size]returns the stack size used when creating new threads if an optional integer size is givenit sets the stack size to be used for creating new threads size can be value that is ( kbor greater and multiple of ( kbfor maximum portability threaderror exception is raised if this operation isn' supported on the system the global interpreter lock the python interpreter is protected by lock that only allows one thread to execute at time even if there are multiple processors available this severely limits the usefulness of threads in compute-intensive programs--in factthe use of threads will often make cpu-bound programs run significantly worse than would be the case if they just sequentially carried out the same work thusthreads should really only be reserved for programs that are primarily concerned with / such as network servers for more compute-intensive tasksconsider using extension modules or the multiprocessing module instead extensions have the option of releasing the interpreter lock and running in parallelprovided that they don' interact with the interpreter when the lock is released the multiprocessing module farms work out to independent subprocesses that aren' restricted by the lock programming with threads although it is possible to write very traditional multithreaded programs in python using various combinations of locks and synchronization primitivesthere is one style of programming that is recommended over all others--and that' to try and organize multithreaded programs as collection of independent tasks that communicate through message queues this is described in the next section (the queue modulealong with an example queuequeue the queue module (named queue in python implements various multiproducermulticonsumer queues that can be used to safely exchange information between multiple threads of execution the queue module defines three different queue classesqueue([maxsize]creates fifo (first-in first-outqueue maxsize is the maximum number of items that can be placed in the queue if maxsize omitted or the queue size is infinite lifoqueue([maxsize]creates lifo (last-infirst-outqueue (also known as stackf lib fl ff