是只有我这样觉得,还是Windows上的新Python futures模块有严重问题?
我现在在使用Windows XP,遇到了新版本Python 3.2的futures模块的问题。看起来我无法让ProcessPoolExecutor
正常工作。以下是一个会话示例:
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
我觉得这里面好像有什么问题。
1 个回答
9
你需要知道的是,concurrent.future
这个模块是依赖于 multiprocessing
模块的,特别是当你使用 ProcessPoolExecutor
的时候。所以有些功能在交互式解释器中可能无法正常工作,想了解更多可以点击 这里。