-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiprocessing_test_processes.py
More file actions
executable file
·64 lines (44 loc) · 1.16 KB
/
multiprocessing_test_processes.py
File metadata and controls
executable file
·64 lines (44 loc) · 1.16 KB
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
63
64
#! /usr/local/bin/python3
from multiprocessing import Process, Queue
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, q):
print('s', number)
time.sleep(3)
# return number + 10
q.put(number)
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()]
# p = Pool()
queues = [Queue() for i in range(30)]
print("start")
# result_list = p.map(wait, arg_list)
processes = [Process(target=wait, args=(i, queues[i],)) for i in range(30)]
# print(result_list)
for p in processes:
p.start()
for p in processes:
p.join()
for q in queues:
print('e', q.get())