forked from PacktPublishing/AdvancedPythonProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample2.py
More file actions
31 lines (23 loc) · 623 Bytes
/
example2.py
File metadata and controls
31 lines (23 loc) · 623 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
# ch6/example2.py
from multiprocessing import Process, current_process
import time
def f1():
pname = current_process().name
print('Starting process %s...' % pname)
time.sleep(2)
print('Exiting process %s...' % pname)
def f2():
pname = current_process().name
print('Starting process %s...' % pname)
time.sleep(4)
print('Exiting process %s...' % pname)
if __name__ == '__main__':
p1 = Process(name='Worker 1', target=f1)
p2 = Process(name='Worker 2', target=f2)
p3 = Process(target=f1)
p1.start()
p2.start()
p3.start()
p1.join()
p2.join()
p3.join()