Frage

I'm using web2py for a project and found that gevent.sleep seems to hang in unexpected disconnects. I'm guessing this is due to improperly handled exception. I can not find it properly written into the documentation, how do I catch, link, or monitor exceptions from gevent.sleep()?

Thank you in advance.

War es hilfreich?

Lösung

Strange guess, it might be wrong. sleep() suspends current Greenlet and resumes next, pending, Greenlet. Most likely it is next Geenlet that runs after sleep() that blocks execution.

If you don't see traceback printed out it is not coming from sleep().

Source code of sleep function:

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)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top