import threading,time,random theVar = 1 class MyThread ( threading.Thread ): myVar=0 def __init__ ( self ): threading.Thread.__init__ ( self ) global theVar print 'This is thread ' + str ( theVar ) + ' speaking.' print 'Hello and good bye.' self.myVar=theVar theVar = theVar + 1 def run (self): for x in xrange ( 10 ): print x,self.myVar time.sleep(random.random()*0.3) for x in xrange ( 10 ): MyThread().start()