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