Compare commits

...

3 Commits

Author SHA1 Message Date
Tyler Goodlet 010d75248e Comment-tag pause points in `asycnio_bp.py`
Thought i already did this but, obvi needed these to make the expect
matches pass in our test.
2025-03-25 12:45:04 -04:00
Tyler Goodlet 47ec7e7a49 Add equiv of `AsyncioCancelled` for aio side
Such that a `TrioCancelled` is raised in the aio task via
`.set_exception()` to explicitly indicate and allow that task to handle
a taskc request from the parent `trio.Task`.
2025-03-25 12:45:04 -04:00
Tyler Goodlet a66caa2397 Drop `asyncio`-canc error from `._exceptions` 2025-03-25 12:45:04 -04:00
2 changed files with 23 additions and 22 deletions

View File

@ -25,7 +25,7 @@ async def bp_then_error(
) -> None:
# sync with ``trio``-side (caller) task
# sync with `trio`-side (caller) task
to_trio.send_nowait('start')
# NOTE: what happens here inside the hook needs some refinement..
@ -33,8 +33,7 @@ async def bp_then_error(
# we set `Lock.local_task_in_debug = 'sync'`, we probably want
# some further, at least, meta-data about the task/actor in debug
# in terms of making it clear it's `asyncio` mucking about.
breakpoint()
breakpoint() # asyncio-side
# short checkpoint / delay
await asyncio.sleep(0.5) # asyncio-side
@ -58,7 +57,6 @@ async def trio_ctx(
# this will block until the ``asyncio`` task sends a "first"
# message, see first line in above func.
async with (
to_asyncio.open_channel_from(
bp_then_error,
# raise_after_bp=not bp_before_started,
@ -69,7 +67,7 @@ async def trio_ctx(
assert first == 'start'
if bp_before_started:
await tractor.pause()
await tractor.pause() # trio-side
await ctx.started(first) # trio-side
@ -111,7 +109,7 @@ async def main(
# pause in parent to ensure no cross-actor
# locking problems exist!
await tractor.pause()
await tractor.pause() # trio-root
if cancel_from_root:
await ctx.cancel()

View File

@ -103,7 +103,16 @@ class AsyncioTaskExited(Exception):
'''
class TrioTaskExited(AsyncioCancelled):
class TrioCancelled(Exception):
'''
Trio cancelled translation (non-base) error
for use with the `to_asyncio` module
to be raised in the `asyncio.Task` to indicate
that the `trio` side raised `Cancelled` or an error.
'''
class TrioTaskExited(Exception):
'''
The `trio`-side task exited without explicitly cancelling the
`asyncio.Task` peer.
@ -406,6 +415,9 @@ class RemoteActorError(Exception):
String-name of the (last hop's) boxed error type.
'''
# TODO, maybe support also serializing the
# `ExceptionGroup.exeptions: list[BaseException]` set under
# certain conditions?
bt: Type[BaseException] = self.boxed_type
if bt:
return str(bt.__name__)
@ -821,8 +833,11 @@ class MsgTypeError(
'''
if (
(_bad_msg := self.msgdata.get('_bad_msg'))
and
isinstance(_bad_msg, PayloadMsg)
and (
isinstance(_bad_msg, PayloadMsg)
or
isinstance(_bad_msg, msgtypes.Start)
)
):
return _bad_msg
@ -1015,18 +1030,6 @@ class MessagingError(Exception):
'''
class AsyncioCancelled(Exception):
'''
Asyncio cancelled translation (non-base) error
for use with the ``to_asyncio`` module
to be raised in the ``trio`` side task
NOTE: this should NOT inherit from `asyncio.CancelledError` or
tests should break!
'''
def pack_error(
exc: BaseException|RemoteActorError,
@ -1206,7 +1209,7 @@ def is_multi_cancelled(
trio.Cancelled in ignore_nested
# XXX always count-in `trio`'s native signal
):
ignore_nested |= {trio.Cancelled}
ignore_nested.update({trio.Cancelled})
if isinstance(exc, BaseExceptionGroup):
matched_exc: BaseExceptionGroup|None = exc.subgroup(