- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionAsProcess.py
More file actions
Latest commit
36 lines (28 loc) · 778 Bytes
/
Copy pathFunctionAsProcess.py
File metadata and controls
36 lines (28 loc) · 778 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
35
'''
Start 3 processes using a function 'f()' as the entry point.
Start 3 instances and wait for completion.
Print activity showing overlapping execution of all processes.
'''
importmultiprocessing
importtime
deflog(proc, msg):
print(' '*2*proc, "Parent"if0==procelseproc, msg)
deff(args):
log(args, "start")
foriinrange(5):
log(args, "tick{0}".format(i))
time.sleep(0.01)
log(args, "done")
if__name__=='__main__':
log(0, "start")
p1=multiprocessing.Process(target=f, args=[1])
p2=multiprocessing.Process(target=f, args=[2])
p3=multiprocessing.Process(target=f, args=[3])
p1.start()
p2.start()
p3.start()
log(0, "wait")
p1.join()
p2.join()
p3.join()
log(0, "done")