realistic threaded programs are usually structured as one or more producer ( workerthreads that add data to queuealong with one or more consumer threads that take the data off the queue and process it in typical threaded guifor exampleproducers may download or compute data and place it on the queuethe consumer--the main gui thread--checks the queue for data periodically with timer event and displays it in the gui when it arrives because the shared queue is thread-safeprograms structured this way automatically synchronize much crossthread data communication the global interpreter lock (gilfinallyas we'll learn in more detail later in this sectionpython' implementation of threads means that only one thread is ever really running its python language code in the python virtual machine at any point in time python threads are true operating system threadsbut all threads must acquire single shared lock when they are ready to runand each thread may be swapped out after running for short period of time (currentlyafter set number of virtual machine instructionsthough this implementation may change in python because of this structurethe python language parts of python threads cannot today be distributed across multiple cpus on multi-cpu computer to leverage more than one cpuyou'll simply need to use process forkingnot threads (the amount and complexity of code required for both are roughly the samemoreoverthe parts of thread that perform long-running tasks implemented as extensions can run truly independently if they release the gil to allow the python code of other threads to run while their task is in progress python codehowevercannot truly overlap in time the advantage of python' implementation of threads is performance--when it was attemptedmaking the virtual machine truly thread-safe reportedly slowed all programs by factor of two on windows and by an even larger factor on linux even nonthreaded programs ran at half speed even though the gil' multiplexing of python language code makes python threads less useful for leveraging capacity on multiple cpu machinesthreads are still useful as programming tools to implement nonblocking operationsespecially in guis moreoverthe newer multiprocessing module we'll meet later offers another solution heretoo--by providing portable thread-like api that is implemented with processesprograms can both leverage the simplicity and programmability of threads and benefit from the scalability of independent processes across cpus despite what you may think after reading the preceding overviewthreads are remarkably easy to use in python in factwhen program is started it is already running threadusually called the "main threadof the process to start newindependent threads of execution within processpython code uses either the low-level _thread module to run function call in spawned threador the higher-level threading module parallel system tools