Start threads to print time at different intervals : Thread « Thread « Python Tutorial






import thread
import time

def print_time(threadName, delay):
    while 1:
        time.sleep(delay)
        print "%s: %s" % (threadName, time.ctime(time.time()))

#Start threads to print time at different intervals
thread.start_new_thread(print_time, ("Thread01",2,))
thread.start_new_thread(print_time, ("Thread02",4,))

while 1:
    pass








17.1.Thread
17.1.1.First thread example
17.1.2.Start threads to print time at different intervals
17.1.3.Loops Executed by a Single Thread
17.1.4.Sleep in a thread
17.1.5.Join threads
17.1.6.Start threads