First thread example : Thread : Thread PYTHON TUTORIALS


PYTHON TUTORIALS » Thread » Thread »

 

First thread example


import threading, time
from sys import stdout

def sleepandprint():
    time.sleep(1)
    print "Hello from both of us."

def threadcode():
    stdout.write("Hello from the new thread.  My name is %sn" % threading.currentThread().getName())
    sleepandprint()

print "Before starting a new thread, my name is", threading.currentThread().getName()

t = threading.Thread(target = threadcode, name = "ChildThread")

t.setDaemon(1)

t.start()
stdout.write("Hello from the main thread.  My name is %sn" % threading.currentThread().getName())
sleepandprint()

t.join()



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Thread
» Thread