-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiThreading.py
More file actions
34 lines (24 loc) · 903 Bytes
/
MultiThreading.py
File metadata and controls
34 lines (24 loc) · 903 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
34
# MultiThreading
from concurrent.futures import thread
from ntpath import join
import threading
from threading import *
from time import sleep
class white (Thread) : # Passing Thread as argument
def run (self) :
for i in range(5) :
print("white")
sleep(1) # sleep for 1 second
class black (Thread) : # Passing Thread as argument
def run (self) :
for i in range(5) :
print("black")
sleep(1) # sleep for 1 second
wht = white()
blk = black()
wht.start() # instead of wht.run
sleep(0.2)
blk.start() # instead of blk.run
wht.join() # main thread will wait for wht.start() to complete
blk.join() # main thread will wait for blk.start() to complete
print("Ending") # main thread will print "Ending" once wht.start() and blk.start() is complete