-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest41_multiprocessing.py
More file actions
37 lines (28 loc) · 899 Bytes
/
test41_multiprocessing.py
File metadata and controls
37 lines (28 loc) · 899 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
36
37
# old way of doing multiprocessing
import multiprocessing
import time
start = time.perf_counter()
def do_something():
print('Sleeping 1 second...')
time.sleep(1)
print('Done Sleeping...')
if __name__ == '__main__':
# do_something()
# do_something()
# p1 = multiprocessing.Process(target=do_something)
# p2 = multiprocessing.Process(target=do_something)
# p1.start()
# p2.start()
# p1.join()
# p2.join()
processes = []
for _ in range(10):
p = multiprocessing.Process(target=do_something)
p.start()
processes.append(p)
# Have to do it this was cause if you added the join to the loop above
# the process whould have to finish before the loop continues execution
for process in processes:
process.join()
finish = time.perf_counter()
print(f'Finished in {round(finish-start,2)} second(s)')