Python Core



Admission Enquiry Form


Multithreading in Python

Example of Multithreading:

#first we need to import threading module
import threading
def fun1():
for x in range(1,100):
print("value of x in thread1 ",x)

def fun2():
for y in range(100,1,-1):
print("value of y in thread2 ",y)

print("Thread1 started")
th1=threading.Thread(target=fun1,name='t1')
th1.start()
print("Thread 2 started ")
th2=threading.Thread(target=fun2,name='t2')
th2.start()
print("program terminated")