join() method:
- It is a dynamic method belongs the Thread class.
- It is used to stop current thread execution until joined thread moved to dead state.
from threading import Thread
import time
class Custom(Thread):
def run(self):
for i in range(1,11):
print("custom : " + str(i))
time.sleep(1)
return
class Default:
def main():
print("Starts @ Default")
c = Custom()
c.start()
c.join()
print("Ends @ Default")
return
Default.main()
from threading import Thread
import time
class Custom(Thread):
res=0 #static
def run(self):
print("Calc starts...")
for i in range(1,Default.n+1):
Custom.res=Custom.res+i
print("Calc ends...")
return
class Default:
n=0 #static
def main():
print("Sum of First N numbers")
Default.n=int(input("Enter n val : "))
obj = Custom()
obj.start()
#time.sleep(10)
obj.join()
print("Result is : "+str(Custom.res))
return
Default.main()