# example of running a function in another thread from time import sleep import threading # a function that blocks for a moment def task(arg1, arg2): print (threading.current_thread().name, " Running!") print ("Identifier: ", threading.current_thread().ident) print ("Native Identifier: ", threading.current_thread().native_id,) # block for a moment sleep(1) # display a message print("arg1=",arg1) print("arg2=",arg2) # create a thread thread = threading.Thread(target=task, args=("One",2)) #display attributes print("Thread Name:",thread.name) print("Background Thread?:",thread.daemon) print("Thread Identifier:",thread.ident) print("Thread Native Identifier:",thread.native_id) print("Alive?:",thread.is_alive()) # run the thread thread.start() #display attributes print("Started Thread Name:",thread.name) print("Alive?:",thread.is_alive()) print("Thread Identifier:",thread.ident) print("Thread Native Identifier:",thread.native_id) # wait for the thread to finish print('Waiting for the thread...') thread.join() print("Ended Thread Name:",thread.name) print("Alive?:",thread.is_alive()) print("Thread Identifier:",thread.ident) print("Thread Native Identifier:",thread.native_id)