# -*- coding: utf-8 -*-
"""
Created on Fri Sep 30 14:01:03 2022
@author: Mahesh.Keshniya
This program demo for multithreading....how two different task can run simulteniously
Python Multithreading--Part1
"""
from threading import Thread, current_thread
import time
def fn_cube(c):
print("\n from cube")
for i in c :
time.sleep(0.2)
y=(i**3)
print("\ncube",y)
print("child2-----",current_thread().name)
def fn_square(c):
print("\n from square")
for i in c :
time.sleep(0.2)
y=(i**2)
print("\nSquare",y)
print("child1-----",current_thread().name)
if __name__ == "__main__":
print("Main thread-----",current_thread().name)
print("new")
x=[2,3,4,5]
t=time.time()
th1 = Thread( target=fn_cube, args=(x,))
th2 = Thread( target=fn_square, args=(x,))
th1.start()
th2.start()
th1.join()
th2.join()
print("total time",time.time()-t)
Comments
Post a Comment