1import _thread
2import time
3
4# Define a function for the thread
5def print_time( threadName, delay):
6 count = 0
7 while count < 5:
8 time.sleep(delay)
9 count += 1
10 print ("%s: %s" % ( threadName, time.ctime(time.time()) ))
11
12# Create two threads as follows
13try:
14 _thread.start_new_thread( print_time, ("Thread-1", 2, ) )
15 _thread.start_new_thread( print_time, ("Thread-2", 4, ) )
16except:
17 print ("Error: unable to start thread")
18
19while 1:
20 pass
21#The program will create two threads that will run the function print_time
22#at the same time with the different values.