I have a problem that I cannot figure out what happened: I was trying to follow a multiprocessing tutorial using the following code:
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())
I ran this piece of code successfully in jupyter notebook but got the following error message when I ran it in 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
so what happened?