2021-12-15 22:42:40 +00:00
|
|
|
# tractor: structured concurrent "actors".
|
|
|
|
# Copyright 2018-eternity Tyler Goodlet.
|
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2021-08-02 16:36:40 +00:00
|
|
|
'''
|
2020-06-29 02:44:16 +00:00
|
|
|
Infection apis for ``asyncio`` loops running ``trio`` using guest mode.
|
2021-08-02 16:36:40 +00:00
|
|
|
|
|
|
|
'''
|
2020-06-29 02:44:16 +00:00
|
|
|
import asyncio
|
2021-11-17 18:20:04 +00:00
|
|
|
from asyncio.exceptions import CancelledError
|
2021-10-08 03:14:34 +00:00
|
|
|
from contextlib import asynccontextmanager as acm
|
2021-11-22 18:08:00 +00:00
|
|
|
from dataclasses import dataclass
|
2020-06-29 02:44:16 +00:00
|
|
|
import inspect
|
|
|
|
from typing import (
|
2020-07-21 14:32:37 +00:00
|
|
|
Any,
|
2020-06-29 02:44:16 +00:00
|
|
|
Callable,
|
2020-10-14 16:51:41 +00:00
|
|
|
AsyncIterator,
|
2020-06-29 02:44:16 +00:00
|
|
|
Awaitable,
|
2021-10-08 03:14:34 +00:00
|
|
|
Optional,
|
2020-06-29 02:44:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
import trio
|
|
|
|
|
2021-11-17 18:20:04 +00:00
|
|
|
from .log import get_logger
|
2020-06-29 02:44:16 +00:00
|
|
|
from ._state import current_actor
|
2021-11-23 21:19:19 +00:00
|
|
|
from ._exceptions import AsyncioCancelled
|
2020-06-29 02:44:16 +00:00
|
|
|
|
|
|
|
log = get_logger(__name__)
|
|
|
|
|
|
|
|
|
2020-07-03 21:33:46 +00:00
|
|
|
__all__ = ['run_task', 'run_as_asyncio_guest']
|
2020-06-29 02:44:16 +00:00
|
|
|
|
|
|
|
|
2021-11-28 17:38:37 +00:00
|
|
|
@dataclass
|
|
|
|
class LinkedTaskChannel(trio.abc.Channel):
|
|
|
|
'''
|
|
|
|
A "linked task channel" which allows for two-way synchronized msg
|
|
|
|
passing between a ``trio``-in-guest-mode task and an ``asyncio``
|
|
|
|
task scheduled in the host loop.
|
|
|
|
|
|
|
|
'''
|
|
|
|
_to_aio: asyncio.Queue
|
|
|
|
_from_aio: trio.MemoryReceiveChannel
|
|
|
|
_to_trio: trio.MemorySendChannel
|
|
|
|
|
|
|
|
_trio_cs: trio.CancelScope
|
|
|
|
_aio_task_complete: trio.Event
|
|
|
|
|
|
|
|
# set after ``asyncio.create_task()``
|
|
|
|
_aio_task: Optional[asyncio.Task] = None
|
|
|
|
_aio_err: Optional[BaseException] = None
|
|
|
|
|
|
|
|
async def aclose(self) -> None:
|
|
|
|
await self._from_aio.aclose()
|
|
|
|
|
|
|
|
async def receive(self) -> Any:
|
|
|
|
async with translate_aio_errors(self):
|
|
|
|
return await self._from_aio.receive()
|
|
|
|
|
|
|
|
async def wait_ayncio_complete(self) -> None:
|
|
|
|
await self._aio_task_complete.wait()
|
|
|
|
|
|
|
|
# def cancel_asyncio_task(self) -> None:
|
|
|
|
# self._aio_task.cancel()
|
|
|
|
|
|
|
|
async def send(self, item: Any) -> None:
|
|
|
|
'''
|
|
|
|
Send a value through to the asyncio task presuming
|
|
|
|
it defines a ``from_trio`` argument, if it does not
|
|
|
|
this method will raise an error.
|
|
|
|
|
|
|
|
'''
|
|
|
|
self._to_aio.put_nowait(item)
|
|
|
|
|
|
|
|
|
2021-04-27 16:20:33 +00:00
|
|
|
def _run_asyncio_task(
|
2021-11-28 17:38:37 +00:00
|
|
|
|
2020-06-29 02:44:16 +00:00
|
|
|
func: Callable,
|
2020-07-03 21:33:46 +00:00
|
|
|
*,
|
2021-04-27 16:20:33 +00:00
|
|
|
qsize: int = 1,
|
2021-10-08 03:14:34 +00:00
|
|
|
provide_channels: bool = False,
|
2020-06-29 02:44:16 +00:00
|
|
|
**kwargs,
|
2021-10-08 03:14:34 +00:00
|
|
|
|
2021-11-28 17:38:37 +00:00
|
|
|
) -> LinkedTaskChannel:
|
2021-10-14 21:33:56 +00:00
|
|
|
'''
|
2021-10-08 03:14:34 +00:00
|
|
|
Run an ``asyncio`` async function or generator in a task, return
|
2020-06-29 02:44:16 +00:00
|
|
|
or stream the result back to ``trio``.
|
2021-04-27 16:20:33 +00:00
|
|
|
|
2021-10-14 21:33:56 +00:00
|
|
|
'''
|
2021-09-18 18:10:21 +00:00
|
|
|
if not current_actor().is_infected_aio():
|
|
|
|
raise RuntimeError("`infect_asyncio` mode is not enabled!?")
|
2020-06-29 02:44:16 +00:00
|
|
|
|
2021-11-22 18:08:00 +00:00
|
|
|
# ITC (inter task comms), these channel/queue names are mostly from
|
|
|
|
# ``asyncio``'s perspective.
|
2021-11-28 17:38:37 +00:00
|
|
|
aio_q = from_trio = asyncio.Queue(qsize) # type: ignore
|
2020-07-21 14:32:37 +00:00
|
|
|
to_trio, from_aio = trio.open_memory_channel(qsize) # type: ignore
|
2020-06-29 02:44:16 +00:00
|
|
|
|
2020-07-03 21:33:46 +00:00
|
|
|
args = tuple(inspect.getfullargspec(func).args)
|
|
|
|
|
|
|
|
if getattr(func, '_tractor_steam_function', None):
|
|
|
|
# the assumption is that the target async routine accepts the
|
|
|
|
# send channel then it intends to yield more then one return
|
|
|
|
# value otherwise it would just return ;P
|
2021-04-27 16:20:33 +00:00
|
|
|
assert qsize > 1
|
2020-07-03 21:33:46 +00:00
|
|
|
|
2021-10-08 03:14:34 +00:00
|
|
|
if provide_channels:
|
|
|
|
assert 'to_trio' in args
|
|
|
|
|
2020-07-03 21:33:46 +00:00
|
|
|
# allow target func to accept/stream results manually by name
|
|
|
|
if 'to_trio' in args:
|
|
|
|
kwargs['to_trio'] = to_trio
|
2021-04-27 16:20:33 +00:00
|
|
|
|
2020-07-03 21:33:46 +00:00
|
|
|
if 'from_trio' in args:
|
2020-07-21 14:32:37 +00:00
|
|
|
kwargs['from_trio'] = from_trio
|
2020-06-29 02:44:16 +00:00
|
|
|
|
|
|
|
coro = func(**kwargs)
|
|
|
|
|
2021-07-28 16:32:46 +00:00
|
|
|
cancel_scope = trio.CancelScope()
|
2021-10-08 03:14:34 +00:00
|
|
|
aio_task_complete = trio.Event()
|
|
|
|
aio_err: Optional[BaseException] = None
|
|
|
|
|
2021-11-28 17:38:37 +00:00
|
|
|
chan = LinkedTaskChannel(
|
|
|
|
aio_q, # asyncio.Queue
|
|
|
|
from_aio, # recv chan
|
|
|
|
to_trio, # send chan
|
|
|
|
|
|
|
|
cancel_scope,
|
|
|
|
aio_task_complete,
|
|
|
|
)
|
|
|
|
|
2021-10-08 03:14:34 +00:00
|
|
|
async def wait_on_coro_final_result(
|
2021-11-17 23:56:23 +00:00
|
|
|
|
2021-10-08 03:14:34 +00:00
|
|
|
to_trio: trio.MemorySendChannel,
|
|
|
|
coro: Awaitable,
|
|
|
|
aio_task_complete: trio.Event,
|
|
|
|
|
|
|
|
) -> None:
|
2021-10-14 21:33:56 +00:00
|
|
|
'''
|
2021-10-08 03:14:34 +00:00
|
|
|
Await ``coro`` and relay result back to ``trio``.
|
|
|
|
|
2021-10-14 21:33:56 +00:00
|
|
|
'''
|
2021-10-08 03:14:34 +00:00
|
|
|
nonlocal aio_err
|
2021-11-28 17:38:37 +00:00
|
|
|
nonlocal chan
|
|
|
|
|
2021-10-08 03:14:34 +00:00
|
|
|
orig = result = id(coro)
|
|
|
|
try:
|
|
|
|
result = await coro
|
2021-11-28 17:38:37 +00:00
|
|
|
except BaseException as aio_err:
|
|
|
|
chan._aio_err = aio_err
|
2021-10-14 21:30:18 +00:00
|
|
|
raise
|
2021-11-17 23:56:23 +00:00
|
|
|
|
2021-11-23 21:19:19 +00:00
|
|
|
else:
|
2021-11-20 17:43:54 +00:00
|
|
|
if (
|
|
|
|
result != orig and
|
|
|
|
aio_err is None and
|
|
|
|
|
|
|
|
# in the ``open_channel_from()`` case we don't
|
|
|
|
# relay through the "return value".
|
|
|
|
not provide_channels
|
|
|
|
):
|
2021-10-08 03:14:34 +00:00
|
|
|
to_trio.send_nowait(result)
|
2020-06-29 02:44:16 +00:00
|
|
|
|
2021-11-23 21:19:19 +00:00
|
|
|
finally:
|
2021-11-22 18:08:00 +00:00
|
|
|
# if the task was spawned using ``open_channel_from()``
|
|
|
|
# then we close the channels on exit.
|
|
|
|
if provide_channels:
|
2021-11-23 21:19:19 +00:00
|
|
|
# only close the sender side which will relay
|
|
|
|
# a ``trio.EndOfChannel`` to the trio (consumer) side.
|
2021-11-22 18:08:00 +00:00
|
|
|
to_trio.close()
|
|
|
|
|
2021-11-20 17:43:54 +00:00
|
|
|
aio_task_complete.set()
|
|
|
|
|
2020-06-29 02:44:16 +00:00
|
|
|
# start the asyncio task we submitted from trio
|
2021-11-28 17:38:37 +00:00
|
|
|
if not inspect.isawaitable(coro):
|
2020-10-14 16:51:41 +00:00
|
|
|
raise TypeError(f"No support for invoking {coro}")
|
2020-07-21 14:32:37 +00:00
|
|
|
|
2021-11-28 17:38:37 +00:00
|
|
|
task = asyncio.create_task(
|
|
|
|
wait_on_coro_final_result(
|
|
|
|
to_trio,
|
|
|
|
coro,
|
|
|
|
aio_task_complete
|
|
|
|
)
|
|
|
|
)
|
|
|
|
chan._aio_task = task
|
|
|
|
|
2021-11-23 21:19:19 +00:00
|
|
|
def cancel_trio(task: asyncio.Task) -> None:
|
2021-10-14 21:30:18 +00:00
|
|
|
'''
|
|
|
|
Cancel the calling ``trio`` task on error.
|
|
|
|
|
|
|
|
'''
|
2021-11-28 17:38:37 +00:00
|
|
|
nonlocal chan
|
|
|
|
aio_err = chan._aio_err
|
2021-11-23 21:19:19 +00:00
|
|
|
|
2021-11-24 17:12:21 +00:00
|
|
|
# only to avoid ``asyncio`` complaining about uncaptured
|
|
|
|
# task exceptions
|
|
|
|
try:
|
|
|
|
task.exception()
|
|
|
|
except BaseException as terr:
|
|
|
|
assert type(terr) is type(aio_err), 'Asyncio task error mismatch?'
|
|
|
|
|
2021-11-23 21:19:19 +00:00
|
|
|
if aio_err is not None:
|
|
|
|
if type(aio_err) is CancelledError:
|
|
|
|
log.cancel("infected task was cancelled")
|
|
|
|
else:
|
2021-11-22 18:08:00 +00:00
|
|
|
aio_err.with_traceback(aio_err.__traceback__)
|
2021-11-20 17:43:54 +00:00
|
|
|
log.exception("infected task errorred:")
|
2021-11-22 18:08:00 +00:00
|
|
|
|
2021-11-23 21:19:19 +00:00
|
|
|
# NOTE: currently mem chan closure may act as a form
|
|
|
|
# of error relay (at least in the ``asyncio.CancelledError``
|
|
|
|
# case) since we have no way to directly trigger a ``trio``
|
|
|
|
# task error without creating a nursery to throw one.
|
|
|
|
# We might want to change this in the future though.
|
|
|
|
from_aio.close()
|
2020-06-29 02:44:16 +00:00
|
|
|
|
|
|
|
task.add_done_callback(cancel_trio)
|
|
|
|
|
2021-11-28 17:38:37 +00:00
|
|
|
return chan
|
2021-04-27 16:20:33 +00:00
|
|
|
|
|
|
|
|
2021-11-20 17:43:54 +00:00
|
|
|
@acm
|
|
|
|
async def translate_aio_errors(
|
2021-08-02 16:36:40 +00:00
|
|
|
|
2021-11-28 17:38:37 +00:00
|
|
|
chan: LinkedTaskChannel,
|
2021-08-02 16:36:40 +00:00
|
|
|
|
2021-11-28 17:38:37 +00:00
|
|
|
) -> AsyncIterator[None]:
|
2021-11-17 18:20:04 +00:00
|
|
|
'''
|
2021-11-20 17:43:54 +00:00
|
|
|
Error handling context around ``asyncio`` task spawns which
|
|
|
|
appropriately translates errors and cancels into ``trio`` land.
|
2021-04-27 16:20:33 +00:00
|
|
|
|
2021-11-17 18:20:04 +00:00
|
|
|
'''
|
2021-11-28 17:38:37 +00:00
|
|
|
aio_err: Optional[BaseException] = None
|
2021-08-02 16:36:40 +00:00
|
|
|
|
2021-11-23 21:19:19 +00:00
|
|
|
def maybe_raise_aio_err(
|
|
|
|
err: Optional[Exception] = None
|
|
|
|
) -> None:
|
2021-11-28 17:38:37 +00:00
|
|
|
aio_err = chan._aio_err
|
2021-11-17 18:20:04 +00:00
|
|
|
if (
|
|
|
|
aio_err is not None and
|
|
|
|
type(aio_err) != CancelledError
|
|
|
|
):
|
2020-10-14 16:51:41 +00:00
|
|
|
# always raise from any captured asyncio error
|
2021-11-23 21:19:19 +00:00
|
|
|
if err:
|
|
|
|
raise aio_err from err
|
|
|
|
else:
|
|
|
|
raise aio_err
|
2021-11-28 17:38:37 +00:00
|
|
|
|
|
|
|
task = chan._aio_task
|
|
|
|
assert task
|
2021-11-22 18:08:00 +00:00
|
|
|
try:
|
|
|
|
yield
|
|
|
|
except (
|
2021-11-23 21:19:19 +00:00
|
|
|
# NOTE: see the note in the ``cancel_trio()`` asyncio task
|
|
|
|
# termination callback
|
|
|
|
trio.ClosedResourceError,
|
|
|
|
):
|
2021-11-28 17:38:37 +00:00
|
|
|
aio_err = chan._aio_err
|
2021-11-23 21:19:19 +00:00
|
|
|
if (
|
|
|
|
task.cancelled() and
|
|
|
|
type(aio_err) is CancelledError
|
|
|
|
):
|
|
|
|
# if an underlying ``asyncio.CancelledError`` triggered this
|
|
|
|
# channel close, raise our (non-``BaseException``) wrapper
|
|
|
|
# error: ``AsyncioCancelled`` from that source error.
|
|
|
|
raise AsyncioCancelled from aio_err
|
2021-11-17 18:20:04 +00:00
|
|
|
|
2021-11-23 21:19:19 +00:00
|
|
|
else:
|
|
|
|
raise
|
2021-09-18 18:10:21 +00:00
|
|
|
finally:
|
2021-11-23 21:19:19 +00:00
|
|
|
# always cancel the ``asyncio`` task if we've made it this far
|
|
|
|
# and it's not done.
|
2021-11-22 18:08:00 +00:00
|
|
|
if not task.done() and aio_err:
|
2021-11-23 21:19:19 +00:00
|
|
|
# assert not aio_err, 'WTF how did asyncio do this?!'
|
2021-10-08 03:14:34 +00:00
|
|
|
task.cancel()
|
2021-04-27 16:20:33 +00:00
|
|
|
|
2021-11-23 21:19:19 +00:00
|
|
|
# if any ``asyncio`` error was caught, raise it here inline
|
|
|
|
# here in the ``trio`` task
|
|
|
|
maybe_raise_aio_err()
|
2021-11-17 18:20:04 +00:00
|
|
|
|
2021-04-27 16:20:33 +00:00
|
|
|
|
2021-11-20 17:43:54 +00:00
|
|
|
async def run_task(
|
|
|
|
func: Callable,
|
|
|
|
*,
|
|
|
|
|
|
|
|
qsize: int = 2**10,
|
|
|
|
**kwargs,
|
|
|
|
|
|
|
|
) -> Any:
|
|
|
|
'''
|
|
|
|
Run an ``asyncio`` async function or generator in a task, return
|
|
|
|
or stream the result back to ``trio``.
|
|
|
|
|
|
|
|
'''
|
|
|
|
# simple async func
|
2021-11-28 17:38:37 +00:00
|
|
|
chan = _run_asyncio_task(
|
2021-11-20 17:43:54 +00:00
|
|
|
func,
|
|
|
|
qsize=1,
|
|
|
|
**kwargs,
|
|
|
|
)
|
2021-11-28 17:38:37 +00:00
|
|
|
with chan._from_aio:
|
2021-11-23 21:19:19 +00:00
|
|
|
# try:
|
2021-11-28 17:38:37 +00:00
|
|
|
async with translate_aio_errors(chan):
|
2021-11-23 21:19:19 +00:00
|
|
|
# return single value that is the output from the
|
|
|
|
# ``asyncio`` function-as-task. Expect the mem chan api to
|
|
|
|
# do the job of handling cross-framework cancellations
|
|
|
|
# / errors via closure and translation in the
|
|
|
|
# ``translate_aio_errors()`` in the above ctx mngr.
|
2021-11-28 17:38:37 +00:00
|
|
|
return await chan.receive()
|
2021-11-22 18:08:00 +00:00
|
|
|
|
|
|
|
|
2021-10-08 03:14:34 +00:00
|
|
|
@acm
|
|
|
|
async def open_channel_from(
|
2021-11-22 18:08:00 +00:00
|
|
|
|
2021-11-28 17:38:37 +00:00
|
|
|
target: Callable[..., Any],
|
2021-10-08 03:14:34 +00:00
|
|
|
**kwargs,
|
|
|
|
|
|
|
|
) -> AsyncIterator[Any]:
|
2021-11-22 18:08:00 +00:00
|
|
|
'''
|
|
|
|
Open an inter-loop linked task channel for streaming between a target
|
|
|
|
spawned ``asyncio`` task and ``trio``.
|
2021-10-08 03:14:34 +00:00
|
|
|
|
2021-11-22 18:08:00 +00:00
|
|
|
'''
|
2021-11-28 17:38:37 +00:00
|
|
|
chan = _run_asyncio_task(
|
2021-11-20 17:43:54 +00:00
|
|
|
target,
|
|
|
|
qsize=2**8,
|
|
|
|
provide_channels=True,
|
|
|
|
**kwargs,
|
|
|
|
)
|
2021-11-28 17:38:37 +00:00
|
|
|
async with chan._from_aio:
|
|
|
|
async with translate_aio_errors(chan):
|
2021-11-22 18:08:00 +00:00
|
|
|
# sync to a "started()"-like first delivered value from the
|
|
|
|
# ``asyncio`` task.
|
2021-11-28 17:38:37 +00:00
|
|
|
first = await chan.receive()
|
2021-11-20 17:43:54 +00:00
|
|
|
|
2021-10-08 03:14:34 +00:00
|
|
|
# stream values upward
|
2021-11-23 21:19:19 +00:00
|
|
|
yield first, chan
|
2021-04-27 16:20:33 +00:00
|
|
|
|
2020-09-12 15:41:17 +00:00
|
|
|
|
2020-06-29 02:44:16 +00:00
|
|
|
def run_as_asyncio_guest(
|
2021-11-07 21:44:41 +00:00
|
|
|
|
2020-07-21 14:32:37 +00:00
|
|
|
trio_main: Callable,
|
2021-11-07 21:44:41 +00:00
|
|
|
|
2020-06-29 02:44:16 +00:00
|
|
|
) -> None:
|
2021-10-14 21:33:56 +00:00
|
|
|
'''
|
|
|
|
Entry for an "infected ``asyncio`` actor".
|
2020-06-29 02:44:16 +00:00
|
|
|
|
2021-11-19 15:31:42 +00:00
|
|
|
Entrypoint for a Python process which starts the ``asyncio`` event
|
|
|
|
loop and runs ``trio`` in guest mode resulting in a system where
|
|
|
|
``trio`` tasks can control ``asyncio`` tasks whilst maintaining
|
|
|
|
SC semantics.
|
2020-06-29 02:44:16 +00:00
|
|
|
|
2021-11-19 15:31:42 +00:00
|
|
|
'''
|
|
|
|
# Uh, oh. :o
|
2020-06-29 02:44:16 +00:00
|
|
|
|
2021-11-19 15:31:42 +00:00
|
|
|
# It looks like your event loop has caught a case of the ``trio``s.
|
2020-06-29 02:44:16 +00:00
|
|
|
|
2021-11-19 15:31:42 +00:00
|
|
|
# :()
|
2020-06-29 02:44:16 +00:00
|
|
|
|
2021-11-19 15:31:42 +00:00
|
|
|
# Don't worry, we've heard you'll barely notice. You might hallucinate
|
|
|
|
# a few more propagating errors and feel like your digestion has
|
|
|
|
# slowed but if anything get's too bad your parents will know about
|
|
|
|
# it.
|
2021-10-08 03:14:34 +00:00
|
|
|
|
2021-11-19 15:31:42 +00:00
|
|
|
# :)
|
2021-10-08 03:14:34 +00:00
|
|
|
|
2020-06-29 02:44:16 +00:00
|
|
|
async def aio_main(trio_main):
|
2020-12-10 18:49:11 +00:00
|
|
|
|
2020-06-29 02:44:16 +00:00
|
|
|
loop = asyncio.get_running_loop()
|
|
|
|
trio_done_fut = asyncio.Future()
|
|
|
|
|
|
|
|
def trio_done_callback(main_outcome):
|
2020-12-10 18:49:11 +00:00
|
|
|
|
2021-10-08 03:14:34 +00:00
|
|
|
print(f"trio_main finished: {main_outcome!r}")
|
2020-06-29 02:44:16 +00:00
|
|
|
trio_done_fut.set_result(main_outcome)
|
|
|
|
|
|
|
|
# start the infection: run trio on the asyncio loop in "guest mode"
|
|
|
|
log.info(f"Infecting asyncio process with {trio_main}")
|
2020-12-10 18:49:11 +00:00
|
|
|
|
2020-06-29 02:44:16 +00:00
|
|
|
trio.lowlevel.start_guest_run(
|
|
|
|
trio_main,
|
|
|
|
run_sync_soon_threadsafe=loop.call_soon_threadsafe,
|
|
|
|
done_callback=trio_done_callback,
|
|
|
|
)
|
2021-11-20 17:43:54 +00:00
|
|
|
return (await trio_done_fut).unwrap()
|
2020-06-29 02:44:16 +00:00
|
|
|
|
|
|
|
# might as well if it's installed.
|
|
|
|
try:
|
|
|
|
import uvloop
|
|
|
|
loop = uvloop.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
2021-11-07 21:44:41 +00:00
|
|
|
return asyncio.run(aio_main(trio_main))
|