回答編集履歴
1
追記
test
CHANGED
@@ -1,6 +1,60 @@
|
|
1
|
-
|
1
|
+
Processを使い値を受け取る方法はいくつかあります。例えばQueueです。
|
2
2
|
|
3
|
+
大まかな流れは、putした後にgetで取り出します。
|
4
|
+
|
5
|
+
```python
|
6
|
+
|
7
|
+
from multiprocessing import Queue, Process
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
def df(s, queue):
|
14
|
+
|
15
|
+
queue.put(s)
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
if __name__ == '__main__':
|
22
|
+
|
23
|
+
sm = [1, 2, 3]
|
24
|
+
|
25
|
+
queue = Queue()
|
26
|
+
|
27
|
+
processes = []
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
for s in sm:
|
32
|
+
|
33
|
+
p = Process(target=df, args=(s, queue))
|
34
|
+
|
35
|
+
p.start()
|
36
|
+
|
37
|
+
processes.append(p)
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
for p in processes:
|
42
|
+
|
43
|
+
p.join()
|
44
|
+
|
45
|
+
result = queue.get()
|
46
|
+
|
47
|
+
print(result)
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
|
56
|
+
|
3
|
-
|
57
|
+
今回の例ですと、ProcessPoolExecutorを使うほうが楽に書けます。
|
4
58
|
|
5
59
|
```python
|
6
60
|
|