Skip to content

Commit 8de6171

Browse files
committed
Merge branch 'master' into no-more-mandatory-buffer-size
2 parents 754fd30 + a9bb934 commit 8de6171

32 files changed

+667
-384
lines changed

ci.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ else
120120

121121
INSTALLDIR=$(python -c "import os, trio; print(os.path.dirname(trio.__file__))")
122122
cp ../setup.cfg $INSTALLDIR
123-
pytest -W error -ra --junitxml=../test-results.xml --run-slow --faulthandler-timeout=60 ${INSTALLDIR} --cov="$INSTALLDIR" --cov-config=../.coveragerc --verbose
123+
pytest -W error -r a --junitxml=../test-results.xml --run-slow ${INSTALLDIR} --cov="$INSTALLDIR" --cov-config=../.coveragerc --verbose
124124

125125
# Disable coverage on 3.8 until we run 3.8 on Windows CI too
126126
# https://github.com/python-trio/trio/pull/784#issuecomment-446438407

docs-requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ babel==2.7.0 # via sphinx
1111
certifi==2019.6.16 # via requests
1212
chardet==3.0.4 # via requests
1313
click==7.0 # via towncrier
14-
docutils==0.14 # via sphinx
14+
docutils==0.15 # via sphinx
1515
idna==2.8
1616
imagesize==1.1.0 # via sphinx
1717
immutables==0.9
@@ -21,12 +21,12 @@ markupsafe==1.1.1 # via jinja2
2121
outcome==1.0.0
2222
packaging==19.0 # via sphinx
2323
pygments==2.4.2 # via sphinx
24-
pyparsing==2.4.0 # via packaging
24+
pyparsing==2.4.1.1 # via packaging
2525
pytz==2019.1 # via babel
2626
requests==2.22.0 # via sphinx
2727
six==1.12.0 # via packaging
2828
sniffio==1.1.0
29-
snowballstemmer==1.2.1 # via sphinx
29+
snowballstemmer==1.9.0 # via sphinx
3030
sortedcontainers==2.1.0
3131
sphinx-rtd-theme==0.4.3
3232
sphinx==2.1.2

docs/source/contributing.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ to get feedback on, feel free to submit it as a PR. (In this case it's
167167
traditional to start the PR title with ``[WIP]``, for "work in
168168
progress".)
169169

170+
When you are submitting your PR, you can include ``Closes #123``,
171+
``Fixes: #123`` or
172+
`some variation <https://help.github.com/en/articles/closing-issues-using-keywords>`__
173+
in either your commit message or the PR description, in order to
174+
automatically close the referenced issue when the PR is merged.
175+
This keeps us closer to the desired state where each open issue reflects some
176+
work that still needs to be done.
177+
170178

171179
.. _pull-request-tests:
172180

docs/source/history.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ Upcoming breaking changes with warnings (i.e., stuff that in 0.2.0
564564

565565
* We took the opportunity to refactor ``run_in_trio_thread`` and
566566
``await_in_trio_thread`` into the new class
567-
:class:`trio.BlockingTrioPortal`
567+
``trio.BlockingTrioPortal``
568568

569569
* The hazmat function ``current_call_soon_thread_and_signal_safe``
570570
is being replaced by :class:`trio.hazmat.TrioToken`

docs/source/reference-core.rst

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ Using channels to pass values between tasks
11091109
different tasks. They're particularly useful for implementing
11101110
producer/consumer patterns.
11111111

1112-
The channel API is defined by the abstract base classes
1112+
The core channel API is defined by the abstract base classes
11131113
:class:`trio.abc.SendChannel` and :class:`trio.abc.ReceiveChannel`.
11141114
You can use these to implement your own custom channels, that do
11151115
things like pass objects between processes or over the network. But in
@@ -1125,14 +1125,23 @@ inside a single process, and for that you can use
11251125
what you use when you're looking for a queue. The main difference
11261126
is that Trio splits the classic queue interface up into two
11271127
objects. The advantage of this is that it makes it possible to put
1128-
the two ends in different processes, and that we can close the two
1129-
sides separately.
1128+
the two ends in different processes without rewriting your code,
1129+
and that we can close the two sides separately.
1130+
1131+
`MemorySendChannel` and `MemoryReceiveChannel` also expose several
1132+
more features beyond the core channel interface:
1133+
1134+
.. autoclass:: MemorySendChannel
1135+
:members:
1136+
1137+
.. autoclass:: MemoryReceiveChannel
1138+
:members:
11301139

11311140

11321141
A simple channel example
11331142
++++++++++++++++++++++++
11341143

1135-
Here's a simple example of how to use channels:
1144+
Here's a simple example of how to use memory channels:
11361145

11371146
.. literalinclude:: reference-core/channels-simple.py
11381147

@@ -1244,14 +1253,13 @@ program above:
12441253
.. literalinclude:: reference-core/channels-mpmc-fixed.py
12451254
:emphasize-lines: 7, 9, 10, 12, 13
12461255

1247-
This example demonstrates using the :meth:`SendChannel.clone
1248-
<trio.abc.SendChannel.clone>` and :meth:`ReceiveChannel.clone
1249-
<trio.abc.ReceiveChannel.clone>` methods. What these do is create
1250-
copies of our endpoints, that act just like the original – except that
1251-
they can be closed independently. And the underlying channel is only
1252-
closed after *all* the clones have been closed. So this completely
1253-
solves our problem with shutdown, and if you run this program, you'll
1254-
see it print its six lines of output and then exits cleanly.
1256+
This example demonstrates using the `MemorySendChannel.clone` and
1257+
`MemoryReceiveChannel.clone` methods. What these do is create copies
1258+
of our endpoints, that act just like the original – except that they
1259+
can be closed independently. And the underlying channel is only closed
1260+
after *all* the clones have been closed. So this completely solves our
1261+
problem with shutdown, and if you run this program, you'll see it
1262+
print its six lines of output and then exits cleanly.
12551263

12561264
Notice a small trick we use: the code in ``main`` creates clone
12571265
objects to pass into all the child tasks, and then closes the original
@@ -1464,8 +1472,8 @@ for working with real, operating-system level,
14641472
:mod:`threading`\-module-style threads. First, if you're in Trio but
14651473
need to push some blocking I/O into a thread, there's
14661474
:func:`run_sync_in_thread`. And if you're in a thread and need
1467-
to communicate back with Trio, you can use a
1468-
:class:`BlockingTrioPortal`.
1475+
to communicate back with Trio, you can use
1476+
:func:`trio.from_thread.run` and :func:`trio.from_thread.run_sync`.
14691477

14701478

14711479
.. _worker-thread-limiting:
@@ -1603,14 +1611,15 @@ Putting blocking I/O into worker threads
16031611
Getting back into the Trio thread from another thread
16041612
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16051613

1606-
.. autoclass:: BlockingTrioPortal
1607-
:members:
1614+
.. autofunction:: trio.from_thread.run
1615+
1616+
.. autofunction:: trio.from_thread.run_sync
16081617

16091618
This will probably be clearer with an example. Here we demonstrate how
16101619
to spawn a child thread, and then use a :ref:`memory channel
16111620
<channels>` to send messages between the thread and a Trio task:
16121621

1613-
.. literalinclude:: reference-core/blocking-trio-portal-example.py
1622+
.. literalinclude:: reference-core/from-thread-example.py
16141623

16151624

16161625
Exceptions and warnings

docs/source/reference-core/blocking-trio-portal-example.py renamed to docs/source/reference-core/from-thread-example.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
import trio
22

3-
def thread_fn(portal, receive_from_trio, send_to_trio):
3+
4+
def thread_fn(receive_from_trio, send_to_trio):
45
while True:
56
# Since we're in a thread, we can't call methods on Trio
6-
# objects directly -- so we use our portal to call them.
7+
# objects directly -- so we use trio.from_thread to call them.
78
try:
8-
request = portal.run(receive_from_trio.receive)
9+
request = trio.from_thread.run(receive_from_trio.receive)
910
except trio.EndOfChannel:
10-
portal.run(send_to_trio.aclose)
11+
trio.from_thread.run(send_to_trio.aclose)
1112
return
1213
else:
1314
response = request + 1
14-
portal.run(send_to_trio.send, response)
15+
trio.from_thread.run(send_to_trio.send, response)
16+
1517

1618
async def main():
17-
portal = trio.BlockingTrioPortal()
1819
send_to_thread, receive_from_trio = trio.open_memory_channel(0)
1920
send_to_trio, receive_from_thread = trio.open_memory_channel(0)
2021

2122
async with trio.open_nursery() as nursery:
2223
# In a background thread, run:
2324
# thread_fn(portal, receive_from_trio, send_to_trio)
2425
nursery.start_soon(
25-
trio.run_sync_in_thread,
26-
thread_fn, portal, receive_from_trio, send_to_trio
26+
trio.run_sync_in_thread, thread_fn, receive_from_trio, send_to_trio
2727
)
2828

2929
# prints "1"
@@ -40,4 +40,5 @@ async def main():
4040
# When we exit the nursery, it waits for the background thread to
4141
# exit.
4242

43+
4344
trio.run(main)

docs/source/reference-hazmat.rst

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,26 @@ All environments provide the following functions:
174174
yourself afterwards.
175175

176176

177+
Unix-specific API
178+
-----------------
179+
180+
`FdStream` supports wrapping Unix files (such as a pipe or TTY) as
181+
a stream.
182+
183+
If you have two different file descriptors for sending and receiving,
184+
and want to bundle them together into a single bidirectional
185+
`~trio.abc.Stream`, then use `trio.StapledStream`::
186+
187+
bidirectional_stream = trio.StapledStream(
188+
trio.hazmat.FdStream(write_fd),
189+
trio.hazmat.FdStream(read_fd)
190+
)
191+
192+
.. autoclass:: FdStream
193+
:show-inheritance:
194+
:members:
195+
196+
177197
Kqueue-specific API
178198
-------------------
179199

@@ -280,11 +300,11 @@ These transitions are accomplished using two function decorators:
280300
function).
281301

282302
An example of where you'd use this is in implementing something
283-
like :meth:`trio.BlockingTrioPortal.run`, which uses
303+
like :func:`trio.from_thread.run`, which uses
284304
:meth:`TrioToken.run_sync_soon` to get into the Trio
285305
thread. :meth:`~TrioToken.run_sync_soon` callbacks are run with
286306
:exc:`KeyboardInterrupt` protection enabled, and
287-
:meth:`~trio.BlockingTrioPortal.run` takes advantage of this to safely set up
307+
:func:`trio.from_thread.run` takes advantage of this to safely set up
288308
the machinery for sending a response back to the original thread, but
289309
then uses :func:`disable_ki_protection` when entering the
290310
user-provided function.

docs/source/reference-io.rst

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,19 @@ Abstract base classes
117117
- :class:`~trio.SocketListener`, :class:`~trio.SSLListener`
118118
* - :class:`SendChannel`
119119
- :class:`AsyncResource`
120-
- :meth:`~SendChannel.send`, :meth:`~SendChannel.send_nowait`
120+
- :meth:`~SendChannel.send`
121121
-
122-
- :func:`~trio.open_memory_channel`
122+
- `~trio.MemorySendChannel`
123123
* - :class:`ReceiveChannel`
124124
- :class:`AsyncResource`
125-
- :meth:`~ReceiveChannel.receive`, :meth:`~ReceiveChannel.receive_nowait`
125+
- :meth:`~ReceiveChannel.receive`
126126
- ``__aiter__``, ``__anext__``
127-
- :func:`~trio.open_memory_channel`
127+
- `~trio.MemoryReceiveChannel`
128+
* - `Channel`
129+
- `SendChannel`, `ReceiveChannel`
130+
-
131+
-
132+
-
128133

129134
.. autoclass:: trio.abc.AsyncResource
130135
:members:
@@ -165,6 +170,10 @@ Abstract base classes
165170
:members:
166171
:show-inheritance:
167172

173+
.. autoclass:: trio.abc.Channel
174+
:members:
175+
:show-inheritance:
176+
168177
.. currentmodule:: trio
169178

170179

@@ -394,6 +403,10 @@ Socket objects
394403
left in an unknown state – possibly open, and possibly
395404
closed. The only reasonable thing to do is to close it.
396405

406+
.. method:: is_readable
407+
408+
Check whether the socket is readable or not.
409+
397410
.. method:: sendfile
398411

399412
`Not implemented yet! <https://github.com/python-trio/trio/issues/45>`__

newsfragments/719.feature.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
We cleaned up the distinction between the "abstract channel interface"
2+
and the "memory channel" concrete implementation.
3+
`trio.abc.SendChannel` and `trio.abc.ReceiveChannel` have been slimmed
4+
down, `trio.MemorySendChannel` and `trio.MemoryReceiveChannel` are now
5+
public types that can be used in type hints, and there's a new
6+
`trio.abc.Channel` interface for future bidirectional channels.

newsfragments/760.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Trio sockets have a new method `~trio.socket.SocketType.is_readable` that allows
2+
you to check whether a socket is readable. This is useful for HTTP/1.1 clients.

0 commit comments

Comments
 (0)