#import threading module
import threading
#import time module
import time
#import random module
import random
#define myThread function taking i as an argument
def myThread(i):
print("Thread {}: started".format(i))
time.sleep(random.randint(1,5))
print("Thread {}: finished".format(i))
#define the main function
def main():
for i in range(4):
thread = threading.Thread(target=myThread, args=(i,))
thread.start()
print("Enumerating: {}".format(threading.enumerate()))
if __name__ == '__main__':
#call main function
main()
Comments
Leave a comment