Compare commits
1 Commits
a69bc00593
...
71cf9e7bd3
Author | SHA1 | Date |
---|---|---|
|
71cf9e7bd3 |
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue