# RunFunctionThread.py from Dr. Karen Works # example of running a function in another thread from time import sleep from threading import Thread # a function that blocks for a moment def task(): # block for a moment sleep(1) # display a message print('task thread running for 1 second') sleep(10) print('task thread running for 3 second') # create a thread thread = Thread(target=task) # run the thread thread.start() # wait for the thread to finish print('Main thread after task thread starts...') sleep(2) print('Main thread 2 seconds after task thread starts...') sleep(2) print('Main thread waiting for the thread after 4 seconds...') thread.join()