|
8 | 8 | import trio
|
9 | 9 |
|
10 | 10 | from ._sync import CapacityLimiter
|
11 |
| -from ._core import enable_ki_protection, disable_ki_protection, RunVar, _entry_queue |
| 11 | +from ._core import enable_ki_protection, disable_ki_protection, RunVar, TrioToken |
12 | 12 |
|
13 | 13 | __all__ = [
|
14 | 14 | "run_sync_in_thread",
|
@@ -181,8 +181,8 @@ async def run_sync_in_thread(sync_fn, *args, cancellable=False, limiter=None):
|
181 | 181 |
|
182 | 182 | ``run_sync_in_thread`` also injects the current ``TrioToken`` into the
|
183 | 183 | spawned thread's local storage so that these threads can re-enter the Trio
|
184 |
| - loop by calling either :func: ``trio.from_thread.run`` or |
185 |
| - :func: ``trio.from_thread.run_sync`` for async or synchronous functions, |
| 184 | + loop by calling either `trio.from_thread.run` or |
| 185 | + `trio.from_thread.run_sync` for async or synchronous functions, |
186 | 186 | respectively.
|
187 | 187 |
|
188 | 188 | Args:
|
@@ -289,13 +289,14 @@ def do_release_then_return_result():
|
289 | 289 | # explicitly to it so it can inject it into thread local storage
|
290 | 290 | def worker_thread_fn(trio_token):
|
291 | 291 | TOKEN_LOCAL.token = trio_token
|
292 |
| - result = outcome.capture(sync_fn, *args) |
293 | 292 | try:
|
294 |
| - token.run_sync_soon(report_back_in_trio_thread_fn, result) |
295 |
| - except trio.RunFinishedError: |
296 |
| - # The entire run finished, so our particular task is certainly |
297 |
| - # long gone -- it must have cancelled. |
298 |
| - pass |
| 293 | + result = outcome.capture(sync_fn, *args) |
| 294 | + try: |
| 295 | + token.run_sync_soon(report_back_in_trio_thread_fn, result) |
| 296 | + except trio.RunFinishedError: |
| 297 | + # The entire run finished, so our particular task is certainly |
| 298 | + # long gone -- it must have cancelled. |
| 299 | + pass |
299 | 300 | finally:
|
300 | 301 | del TOKEN_LOCAL.token
|
301 | 302 |
|
@@ -332,7 +333,7 @@ def _run_fn_as_system_task(cb, fn, *args, trio_token=None):
|
332 | 333 | raised exceptions canceling all tasks should be noted.
|
333 | 334 | """
|
334 | 335 |
|
335 |
| - if trio_token and not isinstance(trio_token, _entry_queue.TrioToken): |
| 336 | + if trio_token and not isinstance(trio_token, TrioToken): |
336 | 337 | raise RuntimeError("Passed kwarg trio_token is not of type TrioToken")
|
337 | 338 |
|
338 | 339 | if not trio_token:
|
|
0 commit comments