Phi*_*lip 5 python queue multiprocessing
我们突然开始在Queue操作上看到"Interrupted system call",如下所示:
Exception in thread Thread-2:
Traceback (most recent call last):
[ . . . ]
result = self.pager.results.get(True, self.WAIT_SECONDS)
File "/usr/lib/python2.5/site-packages/processing-0.52-py2.5-linux-x86_64.egg/processing/queue.py", line 128, in get
if not self._poll(block and (deadline-time.time()) or 0.0):
IOError: [Errno 4] Interrupted system call
Run Code Online (Sandbox Code Playgroud)
这是最近有安全更新的Fedora 10/Python 2.5机器.在此之前,我们的软件运行了大约一年没有发生任何事故,现在它每天都在崩溃.
捕获此异常并重试Queue操作是否正确/必要?
我们没有设置任何信号处理程序,但这是一个Tkinter应用程序可能它设置了一些.清除SIGINT处理程序是否安全,是否可以解决问题?谢谢.
基于comp.lang.python 上的这个帖子和Dan Stromberg的回复,我写了一个RetryQueue,它是Queue的替代品,它为我们完成了工作:
from multiprocessing.queues import Queue
import errno
def retry_on_eintr(function, *args, **kw):
while True:
try:
return function(*args, **kw)
except IOError, e:
if e.errno == errno.EINTR:
continue
else:
raise
class RetryQueue(Queue):
"""Queue which will retry if interrupted with EINTR."""
def get(self, block=True, timeout=None):
return retry_on_eintr(Queue.get, self, block, timeout)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4556 次 |
| 最近记录: |