Skip to content

Commit 41e5361

Browse files
committed
patch chapter5
1 parent 94d6caf commit 41e5361

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

第五章/使用多进程解决斐波那契序列多输入问题.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import concurrent.futures
66
from multiprocessing import, cpu_count, current_process, Manager
77
```
88

9-
上面一些导入模块在之前的章节中提及过,然而,下面中的一些模块我们需要特别注意
9+
上面一些导入模块在之前的章节中提及过,然而,下面的这些模块我们需要特别注意
1010
* cpu_count: 该方法允许获得机器cpu的数量
1111
* current_process: 该方法可以获得当前进程的信息,比如进程名称
1212
* Manager: 该类通过对象的方式允许功在多进程之间共享python对象
1313

1414
下面的代码中我们可以注意到第一个方法有点不同,它将产生15个1到20之间的整数,这些整数将被当作fibo_dict的key使用。
15-
接下来让我们一起来看producer_task方法,如下:
15+
接下来让我们一起来看producer_task方法,如下:
1616
```python
1717
def producer_task(q, fibo_dict):
18-
for i in range(5):
18+
for i in range(15):
1919
value = random.randint(1, 20)
2020
fibo_dict[value] = None
2121

@@ -34,8 +34,8 @@ def consumer_task(q, fibo_dict):
3434
a, b = 0, 1
3535
for item in range(value):
3636
a, b = b, a+b
37-
fibo_dict[value] = a
38-
print("consumer [%s] getting value [%d] from queue..." % (current_process().name, value))
37+
fibo_dict[value] = a
38+
print("consumer [%s] getting value [%d] from queue..." % (current_process().name, value))
3939
```
4040

4141
更进一步,我们来看main函数中的代码,main函数中下面几个变量被定义:

0 commit comments

Comments
 (0)