import time from threading import Thread class THRD( Thread): def __init__( self): Thread.__init__( self) def run(self): count = 0 while 1: count += 1 time.sleep(1) print( "this is thread ") if count > 20: print( " thread ends") break p = THRD() p.start()