-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultithreading.py
46 lines (34 loc) · 1.09 KB
/
Multithreading.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class Hello:
def run(self):
for i in range(5):
print("Hello")
class Hi:
def run(self):
for i in range(5):
print("hi")
thread1=Hello()
thread2=Hi()
t1.run()
t2.run()
#this is not running simultaneously.
# to execute simultaneously & to run 2 thread:
from time import sleep
from threading import *
class Hello(Thread):
def run(self):
for i in range(5):
print("Hello")
sleep(1)
class Hi(Thread):
def run(self):
for in in range(5):
print("Hi")
sleep(1)
thread1=Hello()
thread2=Hi()
thread1.start()
sleep(0.2) #a time gap
thread2.start()
thread1.join()
thread2.join()
print("End of execution")