Python Multi Threading

Program on thread

import threading
import time
class abc(threading.Thread):
def __init__(self,name):
threading.Thread.__init__(self)
self.na=name
threading.Thread.start(self)

    def run(self):
i=1
while i<10:
print(self.na,i)
i=i+1
time.sleep(1)
x=abc("prasad")

for i in range(1,5):
print("main",i)
time.sleep(2)

program on isalive and join

import threading
import time
class abc(threading.Thread):
def __init__(self,name):
threading.Thread.__init__(self)
self.na=name
def run(self):
i=1
while i<10:
print(self.na,i)
i=i+1
time.sleep(1)
x=abc("prasad")
x.start()
print(x.isAlive())

x.join();
print(x.isAlive())

   
program on multiple theads

import threading
import time
class abc(threading.Thread):
def __init__(self,name):
threading.Thread.__init__(self)
self.na=name
def run(self):
i=1
while i<10:
print(self.na,i)
i=i+1
time.sleep(1)
x=abc("prasad")
y=abc("balaram")
z=abc("vision")
x.start()
y.start()
z.start()

print(x.isAlive())

x.join();
print(x.isAlive())

 

 

For
More Explanation
&
Online Classes

Contact Us:
+919885348743