Skip to content

Commit 72b1ad7

Browse files
committed
Merge branch 'master' of github.com:python-trio/trio
2 parents d324d9f + 0b0feb2 commit 72b1ad7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1340
-497
lines changed

.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ source=trio
66
omit=
77
setup.py
88
*/ipython_custom_exc.py
9+
# Omit the generated files in trio/_core starting with _public_
10+
*/trio/_core/_generated_*
911
# The test suite spawns subprocesses to test some stuff, so make sure
1012
# this doesn't corrupt the coverage files
1113
parallel=True

.yapfignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/_generated*

check.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ set -ex
44

55
EXIT_STATUS=0
66

7+
# Test if the generated code is still up to date
8+
python ./trio/_tools/gen_exports.py --test \
9+
|| EXIT_STATUS=$?
10+
711
# Autoformatter *first*, to avoid double-reporting errors
812
# (we'd like to run further autoformatters but *after* merging;
913
# see https://forum.bors.tech/t/pre-test-and-pre-merge-hooks/322)

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ 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
32-
sphinx==2.1.1
32+
sphinx==2.1.2
3333
sphinxcontrib-applehelp==1.0.1 # via sphinx
3434
sphinxcontrib-devhelp==1.0.1 # via sphinx
3535
sphinxcontrib-htmlhelp==1.0.2 # via sphinx

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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ Features
220220
(`#56 <https://github.com/python-trio/trio/issues/56>`__)
221221
- New and improved signal catching API: :func:`open_signal_receiver`. (`#354
222222
<https://github.com/python-trio/trio/issues/354>`__)
223-
- The low level :func:`trio.hazmat.wait_socket_readable`,
224-
:func:`~trio.hazmat.wait_socket_writable`, and
225-
:func:`~trio.hazmat.notify_socket_close` now work on bare socket descriptors,
223+
- The low level ``trio.hazmat.wait_socket_readable``,
224+
``wait_socket_writable``, and
225+
``notify_socket_close`` now work on bare socket descriptors,
226226
instead of requiring a :func:`socket.socket` object. (`#400
227227
<https://github.com/python-trio/trio/issues/400>`__)
228228
- If you're using :func:`trio.hazmat.wait_task_rescheduled` and other low-level
@@ -303,8 +303,8 @@ Features
303303
:exc:`ClosedResourceError`. ``ClosedStreamError`` and ``ClosedListenerError``
304304
are now aliases for :exc:`ClosedResourceError`, and deprecated. For this to
305305
work, Trio needs to know when a resource has been closed. To facilitate this,
306-
new functions have been added: :func:`trio.hazmat.notify_fd_close` and
307-
:func:`trio.hazmat.notify_socket_close`. If you're using Trio's built-in
306+
new functions have been added: ``trio.hazmat.notify_fd_close`` and
307+
``trio.hazmat.notify_socket_close``. If you're using Trio's built-in
308308
wrappers like :class:`~trio.SocketStream` or :mod:`trio.socket`, then you don't
309309
need to worry about this, but if you're using the low-level functions like
310310
:func:`trio.hazmat.wait_readable`, you should make sure to call these

docs/source/reference-core.rst

Lines changed: 20 additions & 12 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

docs/source/reference-hazmat.rst

Lines changed: 25 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -124,113 +124,54 @@ Universally available API
124124

125125
All environments provide the following functions:
126126

127-
.. function:: wait_socket_readable(sock)
127+
.. function:: wait_readable(obj)
128128
:async:
129129

130-
Block until the given :func:`socket.socket` object is readable.
130+
Block until the kernel reports that the given object is readable.
131131

132-
On Unix systems, sockets are fds, and this is identical to
133-
:func:`wait_readable`. On Windows, ``SOCKET`` handles and fds are
134-
different, and this works on ``SOCKET`` handles or Python socket
135-
objects.
132+
On Unix systems, ``obj`` must either be an integer file descriptor,
133+
or else an object with a ``.fileno()`` method which returns an
134+
integer file descriptor. Any kind of file descriptor can be passed,
135+
though the exact semantics will depend on your kernel. For example,
136+
this probably won't do anything useful for on-disk files.
136137

137-
:raises trio.BusyResourceError:
138-
if another task is already waiting for the given socket to
139-
become readable.
140-
141-
.. function:: wait_socket_writable(sock)
142-
:async:
143-
144-
Block until the given :func:`socket.socket` object is writable.
145-
146-
On Unix systems, sockets are fds, and this is identical to
147-
:func:`wait_writable`. On Windows, ``SOCKET`` handles and fds are
148-
different, and this works on ``SOCKET`` handles or Python socket
149-
objects.
138+
On Windows systems, ``obj`` must either be an integer ``SOCKET``
139+
handle, or else an object with a ``.fileno()`` method which returns
140+
an integer ``SOCKET`` handle. File descriptors aren't supported,
141+
and neither are handles that refer to anything besides a
142+
``SOCKET``.
150143

151144
:raises trio.BusyResourceError:
152145
if another task is already waiting for the given socket to
153-
become writable.
154-
:raises trio.ClosedResourceError:
155-
if another task calls :func:`notify_socket_close` while this
156-
function is still working.
157-
158-
159-
.. function:: notify_socket_close(sock)
160-
161-
Notifies Trio's internal I/O machinery that you are about to close
162-
a socket.
163-
164-
This causes any operations currently waiting for this socket to
165-
immediately raise :exc:`~trio.ClosedResourceError`.
166-
167-
This does *not* actually close the socket. Generally when closing a
168-
socket, you should first call this function, and then close the
169-
socket.
170-
171-
On Unix systems, sockets are fds, and this is identical to
172-
:func:`notify_fd_close`. On Windows, ``SOCKET`` handles and fds are
173-
different, and this works on ``SOCKET`` handles or Python socket
174-
objects.
175-
176-
177-
Unix-specific API
178-
-----------------
179-
180-
Unix-like systems provide the following functions:
181-
182-
.. function:: wait_readable(fd)
183-
:async:
184-
185-
Block until the given file descriptor is readable.
186-
187-
.. warning::
188-
189-
This is "readable" according to the operating system's
190-
definition of readable. In particular, it probably won't tell
191-
you anything useful for on-disk files.
192-
193-
:arg fd:
194-
integer file descriptor, or else an object with a ``fileno()`` method
195-
:raises trio.BusyResourceError:
196-
if another task is already waiting for the given fd to
197146
become readable.
198147
:raises trio.ClosedResourceError:
199-
if another task calls :func:`notify_fd_close` while this
148+
if another task calls :func:`notify_closing` while this
200149
function is still working.
201150

202-
203-
.. function:: wait_writable(fd)
151+
.. function:: wait_writable(obj)
204152
:async:
205153

206-
Block until the given file descriptor is writable.
207-
208-
.. warning::
154+
Block until the kernel reports that the given object is writable.
209155

210-
This is "writable" according to the operating system's
211-
definition of writable. In particular, it probably won't tell
212-
you anything useful for on-disk files.
156+
See `wait_readable` for the definition of ``obj``.
213157

214-
:arg fd:
215-
integer file descriptor, or else an object with a ``fileno()`` method
216158
:raises trio.BusyResourceError:
217-
if another task is already waiting for the given fd to
159+
if another task is already waiting for the given socket to
218160
become writable.
219161
:raises trio.ClosedResourceError:
220-
if another task calls :func:`notify_fd_close` while this
162+
if another task calls :func:`notify_closing` while this
221163
function is still working.
222164

223-
.. function:: notify_fd_close(fd)
224165

225-
Notifies Trio's internal I/O machinery that you are about to close
226-
a file descriptor.
166+
.. function:: notify_closing(obj)
227167

228-
This causes any operations currently waiting for this file
229-
descriptor to immediately raise :exc:`~trio.ClosedResourceError`.
168+
Call this before closing a file descriptor or ``SOCKET`` handle
169+
that another task might be waiting on. This will cause any
170+
`wait_readable` or `wait_writable` calls to immediately raise
171+
`~trio.ClosedResourceError`.
230172

231-
This does *not* actually close the file descriptor. Generally when
232-
closing a file descriptor, you should first call this function, and
233-
then actually close it.
173+
This doesn't actually close the object – you still have to do that
174+
yourself afterwards.
234175

235176

236177
Kqueue-specific API

docs/source/reference-io.rst

Lines changed: 24 additions & 16 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

@@ -662,12 +671,12 @@ for them to exit. The interface for doing so consists of two layers:
662671
the standard :func:`subprocess.run` with some additional features
663672
and safer defaults.
664673

665-
* :class:`trio.Process` starts a process in the background and optionally
666-
provides Trio streams for interacting with it (sending input,
667-
receiving output and errors). Using it requires a bit more code
668-
than :func:`~trio.run_process`, but exposes additional capabilities:
669-
back-and-forth communication, processing output as soon as it is generated,
670-
and so forth. It is modelled after the standard :class:`subprocess.Popen`.
674+
* `trio.open_process` starts a process in the background and returns a
675+
`Process` object to let you interact with it. Using it requires a
676+
bit more code than `run_process`, but exposes additional
677+
capabilities: back-and-forth communication, processing output as
678+
soon as it is generated, and so forth. It is modelled after the
679+
standard library :class:`subprocess.Popen`.
671680

672681

673682
.. _subprocess-options:
@@ -713,12 +722,11 @@ course, these defaults can be changed where necessary.
713722
Interacting with a process as it runs
714723
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
715724

716-
If you want more control than :func:`~trio.run_process` affords,
717-
you can spawn a subprocess by creating an instance of
718-
:class:`trio.Process` and then interact with it using its
719-
:attr:`~trio.Process.stdin`,
720-
:attr:`~trio.Process.stdout`, and/or
721-
:attr:`~trio.Process.stderr` streams.
725+
If you want more control than :func:`~trio.run_process` affords, you
726+
can use `trio.open_process` to spawn a subprocess, and then interact
727+
with it using the `Process` interface.
728+
729+
.. autofunction:: trio.open_process
722730

723731
.. autoclass:: trio.Process
724732

0 commit comments

Comments
 (0)