Skip to content

Commit 77bbdac

Browse files
Fixed docstrings and minor nits
1 parent 38f7b40 commit 77bbdac

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

docs/source/reference-core/from-thread-example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
def thread_fn(receive_from_trio, send_to_trio):
55
while True:
66
# Since we're in a thread, we can't call methods on Trio
7-
# objects directly -- so we use our portal to call them.
7+
# objects directly -- so we use trio.from_thread to call them.
88
try:
99
request = trio.from_thread.run(receive_from_trio.receive)
1010
except trio.EndOfChannel:

trio/_threads.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import trio
99

1010
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
1212

1313
__all__ = [
1414
"run_sync_in_thread",
@@ -181,8 +181,8 @@ async def run_sync_in_thread(sync_fn, *args, cancellable=False, limiter=None):
181181
182182
``run_sync_in_thread`` also injects the current ``TrioToken`` into the
183183
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,
186186
respectively.
187187
188188
Args:
@@ -289,13 +289,14 @@ def do_release_then_return_result():
289289
# explicitly to it so it can inject it into thread local storage
290290
def worker_thread_fn(trio_token):
291291
TOKEN_LOCAL.token = trio_token
292-
result = outcome.capture(sync_fn, *args)
293292
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
299300
finally:
300301
del TOKEN_LOCAL.token
301302

@@ -332,7 +333,7 @@ def _run_fn_as_system_task(cb, fn, *args, trio_token=None):
332333
raised exceptions canceling all tasks should be noted.
333334
"""
334335

335-
if trio_token and not isinstance(trio_token, _entry_queue.TrioToken):
336+
if trio_token and not isinstance(trio_token, TrioToken):
336337
raise RuntimeError("Passed kwarg trio_token is not of type TrioToken")
337338

338339
if not trio_token:

0 commit comments

Comments
 (0)