How to use the greenlet.main function in greenlet

To help you get started, we’ve selected a few greenlet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github twisted / twisted / sandbox / radix / gthreadless.py View on Github external
def blockOn(d, desc=None):
    """
    Use me in non-main greenlets to wait for a Deferred to fire.
    """
    g = greenlet.getcurrent()
    if g is greenlet.main:
        raise CalledFromMain("You cannot call blockOn from the main greenlet.")

    if g.parent is greenlet.main:
        mainOrNot =  "(main)"
    else:
        mainOrNot = ""

    #print _desc(g.parent), mainOrNot, "<-", hex(id(g)), "(%s)" % (desc,)

    ## Note ##
    # Notice that this code catches and ignores SystemExit. The
    # greenlet mechanism sends a SystemExit at a blocking greenlet if
    # there is no chance that the greenlet will be fired by anyone
    # else -- that is, no other greenlets have a reference to the one
    # that's blocking.