python - 是我一个人还是 Windows 上新的 Python future 模块出现严重问题

标签 python future executor concurrent.futures

我在 Windows XP 上使用新的 Python 3.2 futures 模块时遇到问题。 看来我无法让 ProcessPoolExecutor 工作。 session 示例:

Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.  

>>> from concurrent import futures  
>>> executor = futures.ProcessPoolExecutor()  
>>> def pio(x):  
...     print("I AM HERE")  
...     return True  
...  
>>> fut = executor.submit(pio, 5)  
>>> Process Process-1:  
Traceback (most recent call last):  
File "C:\Python32\lib\multiprocessing\process.py", line 259, in _bootstrap  
  self.run()  
File "C:\Python32\lib\multiprocessing\process.py", line 114, in run  
  self._target(*self._args, **self._kwargs)  
File "C:\Python32\lib\concurrent\futures\process.py", line 133, in _process_worker  
  call_item = call_queue.get(block=True, timeout=0.1)
File "C:\Python32\lib\multiprocessing\queues.py", line 131, in get
res = self._recv()
AttributeError: 'module' object has no attribute 'pio'

>>> fut.running()
True

看来我这里出了点问题。

最佳答案

你必须知道 concurrent.future模块使用 multiprocessing模块(尤其是当您使用 ProcessPoolExecutor 时),因此某些功能将无法在交互式解释器中运行,阅读更多相关信息 here .

关于python - 是我一个人还是 Windows 上新的 Python future 模块出现严重问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5134668/

相关文章:

python - 在 Python tkinter 中 move 更多对象

asynchronous - 如何有条件地退还不同类型的 future ?

c++ - 将返回 std::future<T> 的函数改编为 std::future<U>

java - 如何中断执行线程

python - Django:set_password 不是散列密码吗?

python - Cloud 9 的语法错误?

用于更新嵌入式设备的 Python 应用程序 - 可行吗?

java - 了解 future /线程

job-scheduling - Spark Streaming 中的作业是如何分配给执行者的?

java - 中断、关闭方法和 ExecutorService