我正在使用web2py进行项目,发现gevent.sleep似乎在意外断开连接时挂起。我猜这是由于处理不当导致异常。我无法正确地将其写入文档中,如何捕获,链接或监视gevent.sleep()中的异常?
提前谢谢。
答案 0 :(得分:0)
奇怪的猜测,这可能是错的。 sleep()暂停当前的Greenlet并恢复下一个待处理的Greenlet。很可能它是在sleep()之后运行的下一个Geenlet阻止执行。
如果你没有看到打印出来的追溯,它就不是来自睡眠()。
睡眠功能的源代码:
def sleep(seconds=0):
"""Put the current greenlet to sleep for at least *seconds*.
*seconds* may be specified as an integer, or a float if fractional seconds
are desired.
If *seconds* is equal to or less than zero, yield control the other coroutines
without actually putting the process to sleep. The :class:`core.idle` watcher
with the highest priority is used to achieve that.
"""
hub = get_hub()
loop = hub.loop
if seconds <= 0:
watcher = loop.idle()
watcher.priority = loop.MAXPRI
else:
watcher = loop.timer(seconds)
hub.wait(watcher)