Compare commits
No commits in common. "b1018a13febf3f97aabc0168d70ab04afe498e6e" and "15f99c313e857c871e7ff71db2188b417a1b700d" have entirely different histories.
b1018a13fe
...
15f99c313e
|
@ -23,10 +23,12 @@ import asyncio
|
||||||
from asyncio.exceptions import (
|
from asyncio.exceptions import (
|
||||||
CancelledError,
|
CancelledError,
|
||||||
)
|
)
|
||||||
|
from asyncio import (
|
||||||
|
QueueShutDown,
|
||||||
|
)
|
||||||
from contextlib import asynccontextmanager as acm
|
from contextlib import asynccontextmanager as acm
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import inspect
|
import inspect
|
||||||
import platform
|
|
||||||
import traceback
|
import traceback
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
|
@ -77,20 +79,6 @@ __all__ = [
|
||||||
'run_as_asyncio_guest',
|
'run_as_asyncio_guest',
|
||||||
]
|
]
|
||||||
|
|
||||||
if (_py_313 := (
|
|
||||||
('3', '13')
|
|
||||||
==
|
|
||||||
platform.python_version_tuple()[:-1]
|
|
||||||
)
|
|
||||||
):
|
|
||||||
# 3.13+ only.. lel.
|
|
||||||
# https://docs.python.org/3.13/library/asyncio-queue.html#asyncio.QueueShutDown
|
|
||||||
from asyncio import (
|
|
||||||
QueueShutDown,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
QueueShutDown = False
|
|
||||||
|
|
||||||
|
|
||||||
# TODO, generally speaking we can generalize this abstraction, a "SC linked
|
# TODO, generally speaking we can generalize this abstraction, a "SC linked
|
||||||
# parent->child task pair", as the same "supervision scope primitive"
|
# parent->child task pair", as the same "supervision scope primitive"
|
||||||
|
@ -360,6 +348,7 @@ def _run_asyncio_task(
|
||||||
trio_task: trio.Task = trio.lowlevel.current_task()
|
trio_task: trio.Task = trio.lowlevel.current_task()
|
||||||
trio_cs = trio.CancelScope()
|
trio_cs = trio.CancelScope()
|
||||||
aio_task_complete = trio.Event()
|
aio_task_complete = trio.Event()
|
||||||
|
aio_err: BaseException|None = None
|
||||||
|
|
||||||
chan = LinkedTaskChannel(
|
chan = LinkedTaskChannel(
|
||||||
_to_aio=aio_q, # asyncio.Queue
|
_to_aio=aio_q, # asyncio.Queue
|
||||||
|
@ -403,7 +392,7 @@ def _run_asyncio_task(
|
||||||
if (
|
if (
|
||||||
result != orig
|
result != orig
|
||||||
and
|
and
|
||||||
chan._aio_err is None
|
aio_err is None
|
||||||
and
|
and
|
||||||
|
|
||||||
# in the `open_channel_from()` case we don't
|
# in the `open_channel_from()` case we don't
|
||||||
|
@ -587,11 +576,7 @@ def _run_asyncio_task(
|
||||||
# normally suppressed unless the trio.Task also errors
|
# normally suppressed unless the trio.Task also errors
|
||||||
#
|
#
|
||||||
# ?TODO, is this even needed (does it happen) now?
|
# ?TODO, is this even needed (does it happen) now?
|
||||||
elif (
|
elif isinstance(aio_err, QueueShutDown):
|
||||||
_py_313
|
|
||||||
and
|
|
||||||
isinstance(aio_err, QueueShutDown)
|
|
||||||
):
|
|
||||||
# import pdbp; pdbp.set_trace()
|
# import pdbp; pdbp.set_trace()
|
||||||
trio_err = AsyncioTaskExited(
|
trio_err = AsyncioTaskExited(
|
||||||
'Task exited before `trio` side'
|
'Task exited before `trio` side'
|
||||||
|
@ -971,10 +956,9 @@ async def translate_aio_errors(
|
||||||
# or an error, we ensure the aio-side gets signalled via
|
# or an error, we ensure the aio-side gets signalled via
|
||||||
# an explicit exception and its `Queue` is shutdown.
|
# an explicit exception and its `Queue` is shutdown.
|
||||||
if ya_trio_exited:
|
if ya_trio_exited:
|
||||||
# XXX py3.13+ ONLY..
|
# raise `QueueShutDown` on next `Queue.get()` call on
|
||||||
# raise `QueueShutDown` on next `Queue.get/put()`
|
# aio side.
|
||||||
if _py_313:
|
chan._to_aio.shutdown()
|
||||||
chan._to_aio.shutdown()
|
|
||||||
|
|
||||||
# pump this event-loop (well `Runner` but ya)
|
# pump this event-loop (well `Runner` but ya)
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue