0

我正在将 web2py 用于一个项目,发现 gevent.sleep 似乎挂在意外断开连接中。我猜这是由于异常处理不当造成的。我找不到正确写入文档的方法,如何从 gevent.sleep() 捕获、链接或监视异常?

先感谢您。

4

1 回答 1

0

奇怪的猜测,可能是错的。sleep() 暂停当前的 Greenlet 并恢复下一个待处理的 Greenlet。很可能是在 sleep() 之后运行的下一个 Geenlet 会阻止执行。

如果您没有看到打印出的回溯,则它不是来自 sleep()。

睡眠函数源码:

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)
于 2013-09-30T12:39:37.117 回答