-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiThreading.py
More file actions
33 lines (26 loc) · 782 Bytes
/
MultiThreading.py
File metadata and controls
33 lines (26 loc) · 782 Bytes
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
# run() − The run() method is the entry point for a thread.
# start() − The start() method starts a thread by calling the run method.
# join([time]) − The join() waits for threads to terminate.
# isAlive() − The isAlive() method checks whether a thread is still executing.
# getName() − The getName() method returns the name of a thread.
# setName() − The setName() method sets the name of a thread.
from threading import *
from time import sleep
class Hello(Thread):
def run(self):
for i in range(5):
print("Hello")
sleep(0.3)
class Hi(Thread):
def run(self):
for i in range(5):
print("Hi")
sleep(0.3)
t1 = Hello()
t2 = Hi()
t1.start()
sleep(0.2)
t2.start()
t1.join()
t2.join()
print("Bye")