Skip to content

Commit 5c81257

Browse files
authored
Merge pull request #1168 from njsmith/fix-blocking-trio-portal-deprecation
Put BlockingTrioPortal back where it's supposed to be.
2 parents 04e92f6 + 2a58e45 commit 5c81257

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

docs/source/history.rst

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ Features
2121
`~trio.abc.ReceiveStream.receive_some`; you can ``await
2222
stream.receive_some()`` with no arguments, and the stream will
2323
automatically pick a reasonable size for you. (`#959 <https://github.com/python-trio/trio/issues/959>`__)
24+
- Threading interfaces have been reworked:
25+
``run_sync_in_worker_thread`` is now `trio.to_thread.run_sync`, and
26+
instead of ``BlockingTrioPortal``, use `trio.from_thread.run` and
27+
`trio.from_thread.run_sync`. What's neat about this is that these
28+
cooperate, so if you're in a thread created by `to_thread.run_sync`,
29+
it remembers which Trio created it, and you can call
30+
``trio.from_thread.*`` directly without having to pass around a
31+
``BlockingTrioPortal`` object everywhere. (`#810 <https://github.com/python-trio/trio/issues/810>`__)
2432
- We cleaned up the distinction between the "abstract channel interface"
2533
and the "memory channel" concrete implementation.
2634
`trio.abc.SendChannel` and `trio.abc.ReceiveChannel` have been slimmed
@@ -86,11 +94,15 @@ Deprecations and Removals
8694
~~~~~~~~~~~~~~~~~~~~~~~~~
8795

8896
- The ``clear`` method on `trio.Event` has been deprecated. (`#637 <https://github.com/python-trio/trio/issues/637>`__)
89-
- ``run_sync_in_worker_thread`` has become `trio.to_thread.run_sync`, in
90-
order to make it shorter, and more consistent with the new
91-
``trio.from_thread``. And ``current_default_worker_thread_limiter`` is
92-
now `trio.to_thread.current_default_thread_limiter`. (Of course the
93-
old names still work with a deprecation warning, for now.) (`#810 <https://github.com/python-trio/trio/issues/810>`__)
97+
- ``BlockingTrioPortal`` has been deprecated in favor of the new
98+
`trio.from_thread`. (`#810
99+
<https://github.com/python-trio/trio/issues/810>`__)
100+
- ``run_sync_in_worker_thread`` is deprecated in favor of
101+
`trio.to_thread.run_sync`. (`#810
102+
<https://github.com/python-trio/trio/issues/810>`__)
103+
- ``current_default_worker_thread_limiter`` is deprecated in favor of
104+
`trio.to_thread.current_default_thread_limiter`. (`#810
105+
<https://github.com/python-trio/trio/issues/810>`__)
94106
- Give up on trying to have different low-level waiting APIs on Unix and
95107
Windows. All platforms now have `trio.hazmat.wait_readable`,
96108
`trio.hazmat.wait_writable`, and `trio.hazmat.notify_closing`. The old

newsfragments/1167.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
In v0.12.0, we accidentally moved ``BlockingTrioPortal`` from ``trio``
2+
to ``trio.hazmat``. It's now been restored to its proper position.
3+
(It's still deprecated though, and will issue a warning if you use it.)

trio/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@
115115
"0.12.0",
116116
issue=810,
117117
),
118+
"BlockingTrioPortal":
119+
_deprecate.DeprecatedAttribute(
120+
_BlockingTrioPortal,
121+
"0.12.0",
122+
issue=810,
123+
instead=from_thread,
124+
),
118125
}
119126

120127
_deprecate.enable_attribute_deprecations(hazmat.__name__)
@@ -143,13 +150,6 @@
143150
"0.12.0",
144151
issue=878,
145152
),
146-
"BlockingTrioPortal":
147-
_deprecate.DeprecatedAttribute(
148-
_BlockingTrioPortal,
149-
"0.12.0",
150-
issue=810,
151-
instead=from_thread,
152-
),
153153
}
154154

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

trio/tests/test_threads.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,3 +560,9 @@ def worker_thread(token):
560560

561561
t = await to_thread_run_sync(worker_thread, token)
562562
assert t == threading.current_thread()
563+
564+
565+
def test_BlockingTrioPortal_deprecated_export(recwarn):
566+
import trio
567+
btp = trio.BlockingTrioPortal
568+
assert btp is BlockingTrioPortal

0 commit comments

Comments
 (0)