python - 为什么 Python 多处理不能在我的 PC 上运行?
问题描述
因此,由于我有一个 16 核 CPU,我想用这个脚本尝试多处理 Python 代码:
import time
NUMBERS = 50000, 50001, 50002, 50003, 50004, 50005, 50006, 50007, 50008, 50009, 50010, 50011, 50012, 50013, 50014, 50015
def factorial(n):
print(f"start: factorial {n}")
f = 1
for i in range(1, n+1):
f*=i
print(f"done: factorial {n}")
return f
import multiprocessing as mp
t0 = time.time()
with mp.Pool() as pool:
result = pool.map(factorial, NUMBERS)
t1 = time.time()
print(f"Excecution took {t1-t0:.4f}")
但是当我在 Anaconda 的 Jupyter 发行版中执行单元格时,它不会输出任何内容,也不会停止。
平台信息:
CPU:i9 9900K
操作系统:Windows 10 专业版(10.0 Build 18362)
蟒蛇版本:1.9.7
Python 3.7.4
Jupyter 在其特殊目录中的 Windows Powershell 中使用以下命令单独启动
Jupyter notebook
解决方案
推荐阅读
- c - 仅使用两个字符打印迷宫
- python - python3.7 sqlalchemy 没有名为“MySQLdb”的模块
- php - 删除或合并多维数组
- git - 无法使用 Git 大文件推送
- java - 我的 Java 作业需要一些帮助,这是一个用于管理电话的简单程序
- c# - 从 ASP.NET (C#) 访问服务器证书
- java - InsufficientAuthenticationException:需要进行身份验证才能获取访问令牌(不允许匿名) - 在进行 ROPC 令牌请求时
- c - 在 foror 循环中使用逗号分隔变量 [C]
- react-native - 在抽屉导航中第二次单击项目时刷新页面内容
- html - 如何隐藏输入文件类型但仍显示上传的文件?