-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiprocessing_test.py
executable file
·62 lines (43 loc) · 1.11 KB
/
multiprocessing_test.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#! /usr/local/bin/python3
from multiprocessing import Pool
import os
import time
def info(title):
print(title)
print('module name:', __name__)
if hasattr(os, 'getppid'):
print('parent process:', os.getppid())
print('process id:', os.getppid())
def f(name):
info('function f')
time.sleep(3)
print('hello', name)
def g(name):
info('function g')
time.sleep(3)
print('hello', name)
def wait(number):
print(number)
time.sleep(3)
return number + 10
# q.put(number + 10)
if __name__ == '__main__':
# info('main line')
# p1 = Process(target=f, args=('bob', ))
# p2 = Process(target=f, args=('john', ))
# p1.start()
# p2.start()
# p1.join()
# p2.join()
arg_list = [i for i in range(5)]
p = Pool()
print("start")
result_list = p.map(wait, arg_list)
# processes = [Process(target=wait, args=(i, queues[i],)) for i in range(5)]
print(result_list)
# for p in processes:
# p.start()
# for p in processes:
# p.join()
# for q in queues:
# print(q.get())