PHP 8.2.30
Preview: runners.py Size: 1.97 KB
//opt/alt/python37/lib64/python3.7/asyncio/runners.py

__all__ = 'run',

from . import coroutines
from . import events
from . import tasks


def run(main, *, debug=False):
    """Execute the coroutine and return the result.

    This function runs the passed coroutine, taking care of
    managing the asyncio event loop and finalizing asynchronous
    generators.

    This function cannot be called when another asyncio event loop is
    running in the same thread.

    If debug is True, the event loop will be run in debug mode.

    This function always creates a new event loop and closes it at the end.
    It should be used as a main entry point for asyncio programs, and should
    ideally only be called once.

    Example:

        async def main():
            await asyncio.sleep(1)
            print('hello')

        asyncio.run(main())
    """
    if events._get_running_loop() is not None:
        raise RuntimeError(
            "asyncio.run() cannot be called from a running event loop")

    if not coroutines.iscoroutine(main):
        raise ValueError("a coroutine was expected, got {!r}".format(main))

    loop = events.new_event_loop()
    try:
        events.set_event_loop(loop)
        loop.set_debug(debug)
        return loop.run_until_complete(main)
    finally:
        try:
            _cancel_all_tasks(loop)
            loop.run_until_complete(loop.shutdown_asyncgens())
        finally:
            events.set_event_loop(None)
            loop.close()


def _cancel_all_tasks(loop):
    to_cancel = tasks.all_tasks(loop)
    if not to_cancel:
        return

    for task in to_cancel:
        task.cancel()

    loop.run_until_complete(
        tasks.gather(*to_cancel, loop=loop, return_exceptions=True))

    for task in to_cancel:
        if task.cancelled():
            continue
        if task.exception() is not None:
            loop.call_exception_handler({
                'message': 'unhandled exception during asyncio.run() shutdown',
                'exception': task.exception(),
                'task': task,
            })

Directory Contents

Dirs: 1 × Files: 25

Name Size Perms Modified Actions
- drwxr-xr-x 2024-05-23 07:07:51
Edit Download
68.19 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
2.03 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
8.58 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
2.11 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
888 B lrw-r--r-- 2024-04-17 17:36:08
Edit Download
8.41 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
25.61 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
2.35 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
12.52 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
15.54 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
124 B lrw-r--r-- 2024-04-17 17:36:08
Edit Download
25.05 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
6.87 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
7.82 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
1.97 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
36.79 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
26.30 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
24.01 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
7.08 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
29.98 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
9.88 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
39.96 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
29.51 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
4.95 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download
1.14 KB lrw-r--r-- 2024-04-17 17:36:08
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).