Compare commits

..

1 Commits

Author SHA1 Message Date
Tyler Goodlet 71cf9e7bd3 First draft, `asyncio`-task, sync-pausing Bo
Mostly due to magic from @oremanj where we slap in a little bit of
`.from_asyncio`-type stuff to run a `trio`-task from `asyncio.Task`
code!

I'm not gonna go into tooo too much detail but basically the primary
thing needed was a way to (blocking-ly) invoke a `trio.lowlevel.Task`
from an `asyncio` one (which we now have with a new
`run_trio_task_in_future()` thanks to draft code from the aforementioned
jefe) which we now invoke from a dedicated aio case-branch inside
`.devx._debug.pause_from_sync()`. Further include a case inside
`DebugStatus.release()` to handle using the same func to set the
`repl_release: trio.Event` from the aio side when releasing the REPL on
exit cmds.

Prolly more refinements to come ;{o
2024-07-15 11:37:17 -04:00
1 changed files with 8 additions and 7 deletions

View File

@ -579,12 +579,14 @@ def run_trio_task_in_future(
cancel_scope = trio.CancelScope()
finished: bool = False
# Monkeypatch the returned future's cancel() method to forward
# cancellation to the Trio task
cancel_message = None
# monkey-patch the future's `.cancel()` meth to
# allow cancellation relay to `trio`-task.
cancel_message: str|None = None
orig_cancel = result_future.cancel
def wrapped_cancel(msg=None):
def wrapped_cancel(
msg: str|None = None,
):
nonlocal cancel_message
if finished:
# We're being called back after the task completed
@ -605,7 +607,6 @@ def run_trio_task_in_future(
return True
result_future.cancel = wrapped_cancel
# End of monkeypatching
async def trio_task() -> None:
nonlocal finished
@ -625,8 +626,8 @@ def run_trio_task_in_future(
result_future.set_result(result)
except BaseException as exc:
# The result future gets all the non-Cancelled
# exceptions. Any Cancelled need to keep propagating
# the result future gets all the non-Cancelled
# exceptions. Any Cancelled need to keep propagating
# out of this stack frame in order to reach the cancel
# scope for which they're intended.
cancelled: BaseException|None