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

发布于 2024-10-19 14:22:44 字数 1119 浏览 1 评论 0 原文

我使用的是 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

我觉得这里有些问题。

I am on windows XP and I have problems with new Python 3.2 futures module.
It seems I am unable to get ProcessPoolExecutor to work.
Session example:

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

It looks like something is wrong here to me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃颗糖壮壮胆 2024-10-26 14:22:44

您必须注意 concurrent.future< /a> 模块使用 multiprocessing 模块(特别是当您使用了 ProcessPoolExecutor),因此某些功能在交互式解释器中无法使用,请阅读有关此内容的更多信息 此处

You have to be aware that the concurrent.future module uses the multiprocessing module (especially when you used the ProcessPoolExecutor), so some functionality will not work in the interactive interpreter, read more about this here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文