Skip to content

Commit c13c60e

Browse files
committed
Rename run_sync_in_worker_thread -> run_sync_in_thread
See python-triogh-810
1 parent 13d27d6 commit c13c60e

24 files changed

+102
-83
lines changed

docs/source/history.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ Upcoming breaking changes with warnings (i.e., stuff that in 0.2.0
560560
functions that take and run a synchronous function. As part of this:
561561

562562
* ``run_in_worker_thread`` is becoming
563-
:func:`run_sync_in_worker_thread`
563+
``run_sync_in_worker_thread``
564564

565565
* We took the opportunity to refactor ``run_in_trio_thread`` and
566566
``await_in_trio_thread`` into the new class
@@ -655,7 +655,7 @@ CPython, or PyPy3 5.9+.
655655
Other changes
656656
~~~~~~~~~~~~~
657657

658-
* :func:`run_sync_in_worker_thread` now has a :ref:`robust mechanism
658+
* :func:`run_sync_in_thread` now has a :ref:`robust mechanism
659659
for applying capacity limits to the number of concurrent threads
660660
<worker-thread-limiting>` (`#10
661661
<https://github.com/python-trio/trio/issues/170>`__, `#57

docs/source/reference-core.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ In acknowledgment of this reality, Trio provides two useful utilities
15661566
for working with real, operating-system level,
15671567
:mod:`threading`\-module-style threads. First, if you're in Trio but
15681568
need to push some blocking I/O into a thread, there's
1569-
:func:`run_sync_in_worker_thread`. And if you're in a thread and need
1569+
:func:`run_sync_in_thread`. And if you're in a thread and need
15701570
to communicate back with Trio, you can use a
15711571
:class:`BlockingTrioPortal`.
15721572

@@ -1589,7 +1589,7 @@ are spawned and the system gets overloaded and crashes. Instead, the N
15891589
threads start executing the first N jobs, while the other
15901590
(100,000 - N) jobs sit in a queue and wait their turn. Which is
15911591
generally what you want, and this is how
1592-
:func:`trio.run_sync_in_worker_thread` works by default.
1592+
:func:`trio.run_sync_in_thread` works by default.
15931593

15941594
The downside of this kind of thread pool is that sometimes, you need
15951595
more sophisticated logic for controlling how many threads are run at
@@ -1636,10 +1636,10 @@ re-using threads, but has no admission control policy: if you give it
16361636
responsible for providing the policy to make sure that this doesn't
16371637
happen – but since it *only* has to worry about policy, it can be much
16381638
simpler. In fact, all there is to it is the ``limiter=`` argument
1639-
passed to :func:`run_sync_in_worker_thread`. This defaults to a global
1639+
passed to :func:`run_sync_in_thread`. This defaults to a global
16401640
:class:`CapacityLimiter` object, which gives us the classic fixed-size
16411641
thread pool behavior. (See
1642-
:func:`current_default_worker_thread_limiter`.) But if you want to use
1642+
:func:`current_default_thread_limiter`.) But if you want to use
16431643
"separate pools" for type A jobs and type B jobs, then it's just a
16441644
matter of creating two separate :class:`CapacityLimiter` objects and
16451645
passing them in when running these jobs. Or here's an example of
@@ -1679,7 +1679,7 @@ time::
16791679
return USER_LIMITERS[user_id]
16801680
except KeyError:
16811681
per_user_limiter = trio.CapacityLimiter(MAX_THREADS_PER_USER)
1682-
global_limiter = trio.current_default_worker_thread_limiter()
1682+
global_limiter = trio.current_default_thread_limiter()
16831683
# IMPORTANT: acquire the per_user_limiter before the global_limiter.
16841684
# If we get 100 jobs for a user at the same time, we want
16851685
# to only allow 3 of them at a time to even compete for the
@@ -1690,17 +1690,17 @@ time::
16901690

16911691

16921692
async def run_in_worker_thread_for_user(user_id, async_fn, *args, **kwargs):
1693-
# *args belong to async_fn; **kwargs belong to run_sync_in_worker_thread
1693+
# *args belong to async_fn; **kwargs belong to run_sync_in_thread
16941694
kwargs["limiter"] = get_user_limiter(user_id)
1695-
return await trio.run_sync_in_worker_thread(asycn_fn, *args, **kwargs)
1695+
return await trio.run_sync_in_thread(asycn_fn, *args, **kwargs)
16961696

16971697

16981698
Putting blocking I/O into worker threads
16991699
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17001700

1701-
.. autofunction:: run_sync_in_worker_thread
1701+
.. autofunction:: run_sync_in_thread
17021702

1703-
.. autofunction:: current_default_worker_thread_limiter
1703+
.. autofunction:: current_default_thread_limiter
17041704

17051705

17061706
Getting back into the Trio thread from another thread

docs/source/reference-core/blocking-trio-portal-example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async def main():
2222
# In a background thread, run:
2323
# thread_fn(portal, receive_from_trio, send_to_trio)
2424
nursery.start_soon(
25-
trio.run_sync_in_worker_thread,
25+
trio.run_sync_in_thread,
2626
thread_fn, portal, receive_from_trio, send_to_trio
2727
)
2828

docs/source/reference-hazmat.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ This logic is a bit convoluted, but accomplishes all of the following:
442442
loop outside of the ``except BlockingIOError:`` block.
443443

444444
These functions can also be useful in other situations. For example,
445-
when :func:`trio.run_sync_in_worker_thread` schedules some work to run
445+
when :func:`trio.run_sync_in_thread` schedules some work to run
446446
in a worker thread, it blocks until the work is finished (so it's a
447447
schedule point), but by default it doesn't allow cancellation. So to
448448
make sure that the call always acts as a checkpoint, it calls

docs/source/reference-io.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ To understand why, you need to know two things.
479479
First, right now no mainstream operating system offers a generic,
480480
reliable, native API for async file or filesystem operations, so we
481481
have to fake it by using threads (specifically,
482-
:func:`run_sync_in_worker_thread`). This is cheap but isn't free: on a
482+
:func:`run_sync_in_thread`). This is cheap but isn't free: on a
483483
typical PC, dispatching to a worker thread adds something like ~100 µs
484484
of overhead to each operation. ("µs" is pronounced "microseconds", and
485485
there are 1,000,000 µs in a second. Note that all the numbers here are

newsfragments/810.removal.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``run_sync_in_worker_thread`` was too much of a mouthful – now it's
2+
just called `run_sync_in_thread` (though the old name still works with
3+
a deprecation warning, for now). Similarly,
4+
``current_default_worker_thread_limiter`` is becoming
5+
`current_default_thread_limiter`.

notes-to-self/blocking-read-hack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def kill_it_after_timeout(new_fd):
2929
async with trio.open_nursery() as nursery:
3030
nursery.start_soon(kill_it_after_timeout, new_fd)
3131
try:
32-
data = await trio.run_sync_in_worker_thread(os.read, new_fd, count)
32+
data = await trio.run_sync_in_thread(os.read, new_fd, count)
3333
except OSError as exc:
3434
if cancel_requested and exc.errno == errno.ENOTCONN:
3535
# Call was successfully cancelled. In a real version we'd

notes-to-self/thread-dispatch-bench.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# minimal a fashion as possible.
33
#
44
# This is useful to get a sense of the *lower-bound* cost of
5-
# run_sync_in_worker_thread
5+
# run_sync_in_thread
66

77
import threading
88
from queue import Queue

trio/__init__.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
)
3333

3434
from ._threads import (
35-
run_sync_in_worker_thread, current_default_worker_thread_limiter,
35+
run_sync_in_thread, current_default_thread_limiter,
3636
BlockingTrioPortal
3737
)
3838

@@ -100,6 +100,20 @@
100100
"library 'subprocess' module"
101101
),
102102
),
103+
"run_sync_in_worker_thread":
104+
_deprecate.DeprecatedAttribute(
105+
run_sync_in_thread,
106+
"0.12.0",
107+
issue=810,
108+
instead=run_sync_in_thread,
109+
),
110+
"current_default_worker_thread_limiter":
111+
_deprecate.DeprecatedAttribute(
112+
current_default_thread_limiter,
113+
"0.12.0",
114+
issue=810,
115+
instead=current_default_thread_limiter,
116+
),
103117
}
104118

105119
# Having the public path in .__module__ attributes is important for:

trio/_core/_entry_queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class TrioToken:
132132
133133
1. It lets you re-enter the Trio run loop from external threads or signal
134134
handlers. This is the low-level primitive that
135-
:func:`trio.run_sync_in_worker_thread` uses to receive results from
135+
:func:`trio.run_sync_in_thread` uses to receive results from
136136
worker threads, that :func:`trio.open_signal_receiver` uses to receive
137137
notifications about signals, and so forth.
138138

0 commit comments

Comments
 (0)