Join (): The parent thread of this child thread will remain blocked until the child thread finishes running.
Setdaemon (True): Daemon thread. The main thread end does not wait for this child thread to end directly.
Import threading
From time import Ctime,sleep
Import time
def music (func):
For I in range (2):
Print ("Begin listening to%s.%s"% (Func,ctime ()))
Sleep (2)
Print ("End Listening%s"%ctime ())
def move (func):
For I in range (2):
Print ("Begin watching at the%s! %s "% (Func,ctime ()))
Sleep (3)
Print (' End watching%s '%ctime ())
Threads = []
T1 = Threading. Thread (target=music,args= (' quiet ',))
Threads.append (T1)
T2 = Threading. Thread (target=move,args= (' Forrest Gump ',))
Threads.append (T2)
if __name__ = = ' __main__ ':
For T in Threads:
# T.setdaemon (True)
T.start ()
# T.join ()
T1.join ()
# T2.join ()
Print ("All over%s"%ctime ())
Python Threading (multithreaded)