“Each thread is still counting. but the sleep() allowed each
thread time to take control and execute. Therefore now the output
is interleaved, with each thread having a turn.“Notice that PROGRAM ENDING is printing out at the beginning
rather than the end. This is because the main loop is executing
faster than the threads can start running. If there are things
which you need to do after a thread or threads have completed, then
you can use join() to block until the completion of a thread. If we
uncomment the join() statement we get:”
Python Threads and Queues
By
Get the Free Newsletter!
Subscribe to Developer Insider for top news, trends, & analysis