(coroutine: Coroutine, loop=None, *, timeout=None)
return val
Call asynchronous code synchronously

    Note that this cannot be used inside an event loop.
Call asynchronous code synchronously
Call asynchronous code synchronously
def block(coroutine: Coroutine, loop=None, *, timeout=None):
    """Call asynchronous code synchronously

    Note that this cannot be used inside an event loop.
    """
    loop = loop or get_event_loop()
    if loop.is_running():
        if hasattr(coroutine, "close"):
            coroutine.close()
        raise CannotBlockHere(
            "It appears you have tried to use a blocking API method "
            "from within an event loop. Unfortunately this is unsupported. "
            "Instead, use the async version of the method."
        )
    try:
        if timeout is None:
            val = loop.run_until_complete(coroutine)
        else:
            val = loop.run_until_complete(asyncio.wait_for(coroutine, timeout=timeout))
    except Exception as e:
        # The intention here is to get sensible stack traces from exceptions within blocking calls
        raise e
    return val
def block ( coroutine : Coroutine , loop = None , * , timeout = None ) : loop = loop or get_event_loop ( ) if loop . is_running ( ) : if hasattr ( coroutine , "close" ) : coroutine . close ( ) raise CannotBlockHere ( "It appears you have tried to use a blocking API method " "from within an event loop. Unfortunately this is unsupported. " "Instead, use the async version of the method." ) try : if timeout is None : val = loop . run_until_complete ( coroutine ) else : val = loop . run_until_complete ( asyncio . wait_for ( coroutine , timeout = timeout ) ) except Exception as e : # The intention here is to get sensible stack traces from exceptions within blocking calls raise e return val