未定义ThreadPoolExecutor[python3]
我正在尝试运行以下代码,这些代码是直接从文档中复制的:: 我得到以下输出:未定义ThreadPoolExecutor[python3],python,multithreading,python-3.x,python-3.4,Python,Multithreading,Python 3.x,Python 3.4,我正在尝试运行以下代码,这些代码是直接从文档中复制的:: 我得到以下输出: Traceback (most recent call last): File "test1.py", line 16, in <module> executor = ThreadPoolExecutor(max_workers=2) NameError: name 'ThreadPoolExecutor' is not defined 回溯(最近一次呼叫最后一次): 文件“test1.py”,
Traceback (most recent call last):
File "test1.py", line 16, in <module>
executor = ThreadPoolExecutor(max_workers=2)
NameError: name 'ThreadPoolExecutor' is not defined
回溯(最近一次呼叫最后一次):
文件“test1.py”,第16行,在
执行器=线程池执行器(最大工作线程数=2)
NameError:未定义名称“ThreadPoolExecutor”
我假设我忘了导入一些东西,但我不知道。使用concurrent.futures导入ThreadPoolExecutor而不是
导入concurrent.futures
,或者保持导入不变,使用executor=concurrent.futures.ThreadPoolExecutor(maxworkers=2)
还请注意,您复制的示例代码被设计为死锁,因此一旦您解决了导入问题,它将无法正常工作。请使用来自concurrent.futures import ThreadPoolExecutor的
,而不是import concurrent.futures
,或者让导入保持原样,并使用executor=concurrent.futures.ThreadPoolExecutor(maxworkers=2)
还要注意的是,您复制的示例代码是为死锁而设计的,因此一旦您解决了导入问题,它将无法正常工作
Traceback (most recent call last):
File "test1.py", line 16, in <module>
executor = ThreadPoolExecutor(max_workers=2)
NameError: name 'ThreadPoolExecutor' is not defined