我有一个问题,我不知道发生了什么: 我尝试使用以下代码学习多处理教程:
import concurrent.futures
import time
start = time.perf_counter()
def do_something(seconds):
print(f'sleeping {seconds} second(s)...')
time.sleep(seconds)
return 'Done sleeping'
with concurrent.futures.ProcessPoolExecutor() as executor:
f1 = executor.submit(do_something, 1)
print(f1.result())
我在jupyter笔记本中成功运行了这段代码,但在Pycharm中运行时收到以下错误消息:
/Users/jiangxu/PycharmProjects/Assign_compartment/venv/bin/python /Users/jiangxu/PycharmProjects/Assign_compartment/multiprocessing.py
Traceback (most recent call last):
File "/Users/jiangxu/PycharmProjects/Assign_compartment/multiprocessing.py", line 14, in <module>
with concurrent.futures.ProcessPoolExecutor() as executor:
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/__init__.py", line 43, in __getattr__
from .process import ProcessPoolExecutor as pe
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/process.py", line 53, in <module>
import multiprocessing as mp
File "/Users/jiangxu/PycharmProjects/Assign_compartment/multiprocessing.py", line 14, in <module>
with concurrent.futures.ProcessPoolExecutor() as executor:
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/__init__.py", line 43, in __getattr__
from .process import ProcessPoolExecutor as pe
ImportError: cannot import name 'ProcessPoolExecutor' from 'concurrent.futures.process' (/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/process.py)
Process finished with exit code 1
发生了什么事
我也有同样的问题。这是因为python文件的名称是“multiprocessing”,所以您要做的就是更改它
相关问题 更多 >
编程相关推荐