def run_in_loop(f: Coroutine[(Any, Any, T)], loop: Optional[asyncio.AbstractEventLoop]=None) -> T:
    "Execute the awaitable in the passed loop.\n\n    If no loop is passed, the currently existing one is used or a new one is created\n    if no loop has been started in the current context.\n\n    After the awaitable is finished, all remaining tasks on the loop will be\n    awaited as well (background tasks).\n\n    WARNING: don't use this if there are never ending background tasks scheduled.\n        in this case, this function will never return.\n\n    Args:\n       f: function to execute\n       loop: loop to use for the execution\n\n    Returns:\n        return value from the function\n    "
    if (loop is None):
        try:
            loop = asyncio.get_event_loop()
        except RuntimeError:
            loop = asyncio.new_event_loop()
            asyncio.set_event_loop(loop)
    result = loop.run_until_complete(f)
    pending = asyncio.Task.all_tasks()
    loop.run_until_complete(asyncio.gather(*pending))
    return result
Execute the awaitable in the passed loop.

If no loop is passed, the currently existing one is used or a new one is created
if no loop has been started in the current context.

After the awaitable is finished, all remaining tasks on the loop will be
awaited as well (background tasks).

WARNING: don't use this if there are never ending background tasks scheduled.
    in this case, this function will never return.

Args:
   f: function to execute
   loop: loop to use for the execution

Returns:
    return value from the function
def run_in_loop(f: Coroutine[(Any, Any, T)], loop: Optional[asyncio.AbstractEventLoop]=None) -> T:
    "Execute the awaitable in the passed loop.\n\n    If no loop is passed, the currently existing one is used or a new one is created\n    if no loop has been started in the current context.\n\n    After the awaitable is finished, all remaining tasks on the loop will be\n    awaited as well (background tasks).\n\n    WARNING: don't use this if there are never ending background tasks scheduled.\n        in this case, this function will never return.\n\n    Args:\n       f: function to execute\n       loop: loop to use for the execution\n\n    Returns:\n        return value from the function\n    "
    if (loop is None):
        try:
            loop = asyncio.get_event_loop()
        except RuntimeError:
            loop = asyncio.new_event_loop()
            asyncio.set_event_loop(loop)
    result = loop.run_until_complete(f)
    pending = asyncio.Task.all_tasks()
    loop.run_until_complete(asyncio.gather(*pending))
    return result