Skip to content

Commit 84bfc2e

Browse files
authored
Merge pull request #26 from python-trio/fix1
Release 0.8.0
2 parents c6c9c54 + 4cc04aa commit 84bfc2e

24 files changed

Lines changed: 210 additions & 276 deletions

.appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ environment:
88
#- PYTHON: "C:\\Python35-x64"
99
- PYTHON: "C:\\Python36"
1010
- PYTHON: "C:\\Python36-x64"
11+
- PYTHON: "C:\\Python37"
12+
- PYTHON: "C:\\Python37-x64"
1113

1214
build_script:
1315
- "git --no-pager log -n2"

.travis.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@ language: python
22
python:
33
- 3.6
44
- 3.6-dev
5-
- 3.7-dev
65
sudo: false
76
dist: trusty
87

98
matrix:
109
include:
10+
# As of 2018-07-05, Travis's 3.7 and 3.8 builds only work if you
11+
# use dist: xenial AND sudo: required
12+
# See: https://github.com/python-trio/trio/pull/556#issuecomment-402879391
13+
- python: 3.7
14+
dist: xenial
15+
sudo: required
16+
- python: 3.7-dev
17+
dist: xenial
18+
sudo: required
19+
- python: 3.8-dev
20+
dist: xenial
21+
sudo: required
1122
# - os: linux
1223
# language: generic
1324
# env: USE_PYPY_RELEASE_VERSION=5.9-beta
@@ -18,14 +29,12 @@ matrix:
1829
- os: osx
1930
language: generic
2031
env: MACPYTHON=3.6.3
21-
- os: linux
22-
language: python
23-
python: 3.6
32+
- python: 3.6
2433
env: CHECK_DOCS=1
25-
- os: linux
26-
language: python
27-
python: 3.6
34+
- python: 3.6
2835
env: CHECK_FORMATTING=1
36+
allow_failures:
37+
- python: 3.8-dev
2938

3039
script:
3140
- ci/travis.sh

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test:
4343

4444

4545
tag:
46-
@git tag v$(shell python3 setup.py -V)
46+
@-git tag v$(shell python3 setup.py -V)
4747

4848
pypi: tag
4949
@if python3 setup.py -V 2>/dev/null | grep -qs + >/dev/null 2>&1 ; \

debian/changelog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
trio-asyncio (0.8.0-1) unstable; urgency=medium
2+
3+
* Fix Trio dependency
4+
* Override asyncio's process-global loop policy handling
5+
6+
-- Matthias Urlichs <matthias@urlichs.de> Fri, 03 Aug 2018 13:37:28 +0200
7+
18
trio-asyncio (0.7.5-3) unstable; urgency=medium
29

310
* depend on outcome

debian/control

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Maintainer: Matthias Urlichs <matthias@urlichs.de>
33
Section: python
44
Priority: optional
55
Build-Depends: dh-python, python3-setuptools, python3-all, debhelper (>= 9),
6-
python3-trio (>= 0.4.0),
6+
python3-trio (>= 0.5.0),
77
python3-pytest-trio,
88
python3-pytest-runner,
99
python3-outcome,
@@ -13,7 +13,7 @@ Homepage: https://github.com/smurfix/trio-asyncio
1313
Package: python3-trio-asyncio
1414
Architecture: all
1515
Depends: ${misc:Depends}, ${python3:Depends},
16-
python3-trio (>= 0.4.0),
16+
python3-trio (>= 0.5.0),
1717
python3-outcome,
1818
Description: Re-implementation of the asyncio mainloop on top of Trio
1919
trio_asyncio allows you to call asyncio code from within Trio,

docs/source/conf.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
("py:class", "CapacityLimiter-like object"),
3131
("py:class", "bytes-like"),
3232
("py:class", "None"),
33-
3433
("py:func", "trio_asyncio.wait_for_child"),
3534
("py:func", "trio_asyncio.run_future"),
3635
("py:func", "trio_asyncio.run_coroutine"),
@@ -118,7 +117,6 @@
118117
# If true, `todo` and `todoList` produce output, else they produce nothing.
119118
todo_include_todos = False
120119

121-
122120
# -- Options for HTML output ----------------------------------------------
123121

124122
# The theme to use for HTML and HTML Help pages. See the documentation for
@@ -152,13 +150,11 @@
152150
# so a file named "default.css" will overwrite the builtin "default.css".
153151
html_static_path = ['_static']
154152

155-
156153
# -- Options for HTMLHelp output ------------------------------------------
157154

158155
# Output file base name for HTML help builder.
159156
htmlhelp_basename = 'trio-asyncio-doc'
160157

161-
162158
# -- Options for LaTeX output ---------------------------------------------
163159

164160
latex_elements = {
@@ -183,28 +179,23 @@
183179
# (source start file, target name, title,
184180
# author, documentclass [howto, manual, or own class]).
185181
latex_documents = [
186-
(master_doc, 'trio-asyncio.tex', 'Trio Documentation',
187-
author, 'manual'),
182+
(master_doc, 'trio-asyncio.tex', 'Trio Documentation', author, 'manual'),
188183
]
189184

190-
191185
# -- Options for manual page output ---------------------------------------
192186

193187
# One entry per manual page. List of tuples
194188
# (source start file, name, description, authors, manual section).
195-
man_pages = [
196-
(master_doc, 'trio-asyncio', 'trio-asyncio Documentation',
197-
[author], 1)
198-
]
199-
189+
man_pages = [(master_doc, 'trio-asyncio', 'trio-asyncio Documentation', [author], 1)]
200190

201191
# -- Options for Texinfo output -------------------------------------------
202192

203193
# Grouping the document tree into Texinfo files. List of tuples
204194
# (source start file, target name, title, author,
205195
# dir menu entry, description, category)
206196
texinfo_documents = [
207-
(master_doc, 'trio-asyncio', 'trio-asyncio Documentation',
208-
author, 'trio-asyncio', 'A re-implementation of the asyncio mainloop on top of Trio',
209-
'Miscellaneous'),
197+
(
198+
master_doc, 'trio-asyncio', 'trio-asyncio Documentation', author, 'trio-asyncio',
199+
'A re-implementation of the asyncio mainloop on top of Trio', 'Miscellaneous'
200+
),
210201
]

docs/source/index.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ With trio-asyncio, you can:
1717

1818
* incrementally convert your code to Trio. Start with a Trio mainloop, call
1919
your existing asyncio code, then successively convert procedures to Trio
20-
conventions.
20+
calling conventions.
2121

2222
* use any asyncio-capable library.
2323

2424
* use trio-asyncio as a building block for convincing other async-ish
2525
libraries (Twisted, Promise, …) to be compatible with Trio.
2626

27-
Trio-Asyncio passes the complete Python 3.6 test suite for asyncio. The
28-
test suites for some well-known libraries like aiohttp also Just Work.
27+
Trio-Asyncio passes the test suite of some complex programs like
28+
``home-assistant``.
2929

30-
There's also compatibility code for not running the asyncio loop
31-
continuously, as in repeated run_until_complete / run_forever-and-call-stop
32-
calls. This mode will probably not be supported forever, but for now it works
33-
well.
30+
In the past, the complete Python 3.6 test suite for asyncio and the tests
31+
for some well-known libraries like aiohttp also Just Work(ed). This is no
32+
longer the case because these tests rely heavily on stopping and restarting
33+
the ``asyncio`` event loop. ``trio_asyncio`` no longer supports this.
3434

3535
Helpful facts:
3636

docs/source/usage.rst

Lines changed: 29 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -94,108 +94,56 @@ You cannot restart the loop, nor would you want to.
9494
Asyncio main loop.
9595
++++++++++++++++++
9696

97-
Short answer: don't.
97+
Doesn't work. However: read on.
9898

9999
.. _native-loop:
100100

101-
Native Mode
102-
-----------
103-
104-
What you really want to do is to use a Trio main loop, and run your asyncio
105-
code in its context. In other words, you should transform this code::
101+
What you really want to do is to use a Trio main loop. You then run your
102+
complete asyncio code in its context. In other words, you should transform
103+
this code::
106104

107105
def main():
108106
loop = asyncio.get_event_loop()
109107
loop.run_until_complete(async_main())
110108
109+
or (Python 3.7 ++)::
110+
111+
def main():
112+
asyncio.run(async_main())
113+
111114
to this::
112115

113116
async def trio_main():
114-
await loop.run_asyncio(async_main)
117+
await trio_asyncio.run_asyncio(async_main)
115118

116119
def main():
117120
trio_asyncio.run(trio_main)
118121

119-
Beside this, no changes to your code are required.
120-
121-
Compatibility Mode
122-
------------------
123-
124-
You still can do things "the asyncio way": the to-be-replaced code from the
125-
:ref:`previous section <native-loop>`
126-
still works – or at least it attempts to work::
127-
128-
import asyncio
129-
import trio_asyncio
130-
asyncio.set_event_loop_policy(trio_asyncio.TrioPolicy())
131-
132-
def main():
133-
loop = asyncio.get_event_loop()
134-
loop.run_until_complete(async_main())
135-
136-
.. warning::
137-
138-
tl;dr: Don't use Compatibility Mode in production code.
139-
140-
However, this is only possible because this mode starts a separate thread
141-
which executes the asyncio main
142-
loop. It runs in lock-step with the code that calls ``loop.run_forever()``
143-
or ``loop.run_until_complete(coro)``. Signals etc. get
144-
delegated if possible (except for [SIGCHLD]_). Thus, while there should be no
145-
concurrency issues, you may still experience hard-to-debug problems.
122+
That's all you need to to to support cross-calling from asyncio to trio
123+
code, or vice versa. You still need to use adapters, though:
124+
:ref:`see below <cross-calling>` for details.
146125

147-
.. [SIGCHLD] Python requires you to register SIGCHLD handlers in the main
148-
thread, but doesn't run them at all when waiting for another thread.
149-
150-
Use :func:`trio_asyncio.wait_for_child` instead.
126+
If your program's start-up code consists of more than one
127+
``loop.run_until_complete`` or ``loop.run_forever`` calls, and/or it
128+
accesses the asyncio mainloop outside of these two calls, you may have to
129+
do some refactoring. Sorry about that.
151130

152-
.. autodoc: trio_asyncio.wait_for_child
153-
154-
``loop.stop()`` tells the loop to suspend itself. You can restart it
155-
with another call to ``loop.run_forever()`` or ``loop.run_until_complete(coro)``,
156-
just as with a regular asyncio loop.
157-
158-
If you use a compatibility-mode loop in a separate thread, you *must* stop and close it
159-
before terminating that thread. Otherwise your thread will leak resources.
160-
161-
In a multi-threaded program, globally setting the event loop policy may not
162-
be a good idea. If you want to run trio-asyncio in a separate thread, you
163-
might get away with using ``TrioPolicy().new_event_loop()`` to create a new
164-
event loop – but a far better idea is to use native mode.
165-
166-
.. note::
167-
168-
Compatibility mode has been added to verify that various test suites,
169-
most notably the tests from asyncio itself, continue to work. In a
170-
real-world program with a long-running asyncio mainloop, you *really*
171-
want to use a :ref:`native-mode main loop <native-loop>` instead.
172-
173-
The authors reserve the right to not fix compatibility mode bugs, or
174-
even to remove compatibility mode entirely.
175-
176-
.. autoclass:: trio_asyncio.sync.SyncTrioEventLoop
177-
178-
Stopping
179-
--------
180-
181-
Call ``loop.stop()`` as usual.
182-
183-
Before stopping, the loop will process all outstanding callbacks.
131+
Compatibility mode
132+
++++++++++++++++++
184133

185-
Closing
186-
-------
134+
… or, running ``trio_asyncio`` on top of an unmodified ``asyncio`` main loop.
187135

188-
A synchronous loop starts a separate thread for running the asynchronous
189-
part of your code. You **must** call ``loop.close()`` before abandoning the
190-
loop.
136+
Unfortunately, we had to discontinue support for this mode. The code was
137+
too intrusive and not particularly stable, caused problems with debugging,
138+
and crashed ``asyncio`` when ``trio_asyncio`` was imported after starting
139+
the asyncio mainloop.
191140

192-
.. note::
141+
``trio_asyncio`` still contains the code, as it is required to run
142+
``asyncio``'s testcases, which pretty much require synchronous mode.
143+
However, if you want to run this in production you'd neet to jump through
144+
various hoops which are neither supported nor documented. Sorry.
193145

194-
This is not a problem in "normal" programs – when the program
195-
terminates, the loop dies along with it. However, when testing you don't
196-
want to leave 1000 asyncio threads lying around.
197-
198-
This also applies in multi-threaded programs with more than one event loop.
146+
.. _cross-calling:
199147

200148
---------------
201149
Cross-calling

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ test=pytest
33
[flake8]
44
max-line-length=99
55
ignore=E402,E731,E127,E502,E123,W503
6-
[pytest]
6+
[tool:pytest]
77
addopts = -p no:asyncio

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"""
5252

5353
install_requires = [
54-
"trio ~= 0.4.0",
54+
"trio >= 0.5.0",
5555
"async_generator >= 1.6",
5656
"outcome",
5757
]

0 commit comments

Comments
 (0)