Thread creation and sleep function in python part 1

Publié le: 04 avril 2020
sur la chaîne: Roshni Thanka
229
5

Thread creation and sleep function in python
Program discussed

from threading import Thread
import threading
import time,random


class mythread(Thread):
def __init__(self,n):
Thread.__init__(self,name=n)

def run(self):
print("The child thread name is :",self.getName())
r=random.randint(1,5)
time.sleep(r)
print(self.getName()," sleep for :",r)


if __name__=="__main__":
print("the parent thread is :",threading.current_thread().getName())
li=[]
no=int(input("Enter the no of thread to create"))

for i in range(no):
li.append(mythread("rosh "+str(i+1)))
for j in li:
j.start()


Sur cette page du site, vous pouvez voir la vidéo en ligne Thread creation and sleep function in python part 1 durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Roshni Thanka 04 avril 2020, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 229 fois et il a aimé 5 téléspectateurs. Bon visionnage!