may 17, 2017 python language summit - nathaniel j. smithnjs/misc/trio-language-summit-2017.pdf ·...
TRANSCRIPT
![Page 1: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/1.jpg)
Trioa report from the
wilds of async
Nathaniel J. SmithMay 17, 2017
Python Language Summit
Slides:tinyurl.com/trio-language-summit
![Page 2: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/2.jpg)
+
![Page 3: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/3.jpg)
Outline● You fool, why are you writing a new async
library?● Trio’s approach● A litany of complaints
![Page 4: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/4.jpg)
Outline● You fool, why are you writing a new async
library?● Trio’s approach● A litany of complaints
![Page 5: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/5.jpg)
asyncio is thestandard async library
“Ideally all third party frameworks would give up their own event loop implementation in favor of the standard implementation”
– Guido, PEP 3156
![Page 6: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/6.jpg)
async: the story so far
![Page 7: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/7.jpg)
Condensed from https://twistedmatrix.com/documents/current/core/howto/defer-intro.html
![Page 8: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/8.jpg)
async: the story so far● Twisted etc. couldn’t use Python to express
control flow, so they invented complicated data structures that do the same thing in a clunkier way.
● asyncio standardized those data structures...● ...then Yury added async/await to make
them easier to use...● ...then Dave Beazley pointed out: now that
we have async/await, can’t we just… use Python instead?
![Page 9: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/9.jpg)
“[…] curio is a beacon of clarity compared to asyncio. However, asyncio […] must continue to support its existing APIs, […] whether we like them or not.
I would love to see a design for a new API that focuses more on coroutines. But it should be a new PEP aimed at Python 3.7 or 3.8.”
– Guido, https://mail.python.org/pipermail/ async-sig/2016-November/000175.html
![Page 10: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/10.jpg)
Outline● You fool, why are you writing a new async
library?● Trio’s approach● A litany of complaints
![Page 11: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/11.jpg)
https://gist.github.com/njsmith/b7bdc9cf153dc73cebd7b64fd5d39e0b
![Page 12: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/12.jpg)
= +
https://gist.github.com/njsmith/b7bdc9cf153dc73cebd7b64fd5d39e0b
![Page 13: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/13.jpg)
async functions
= +
https://gist.github.com/njsmith/b7bdc9cf153dc73cebd7b64fd5d39e0b
![Page 14: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/14.jpg)
async functions
nurseries= +
https://gist.github.com/njsmith/b7bdc9cf153dc73cebd7b64fd5d39e0b
![Page 15: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/15.jpg)
async functions
nurseries
cancellation
= +
https://gist.github.com/njsmith/b7bdc9cf153dc73cebd7b64fd5d39e0b
![Page 16: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/16.jpg)
async functions
nurseries
cancellation
= +
https://gist.github.com/njsmith/b7bdc9cf153dc73cebd7b64fd5d39e0b
Not included:- futures, callbacks- implicit concurrency- lost exceptions
![Page 17: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/17.jpg)
Outline● You fool, why are you writing a new async
library?● Trio’s approach● A litany of complaints
![Page 18: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/18.jpg)
https://github.com/python-trio/trio/issues/103
![Page 19: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/19.jpg)
(Just kidding)
![Page 20: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/20.jpg)
Actual language issues● .throw() is broken / adding Result builtin?● Warning: coroutine ‘...’ was never awaited● MultiError exception handling
– Make traceback objects instantiable / mutable / subclassable
– Mechanism to disable implicit chaining– More standard way to override exception printing?– More ergonomic MultiError handlers?
● Async generator cleanup / PEP 533Slides:tinyurl.com/trio-language-summit
![Page 21: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/21.jpg)
Actual language issues● .throw() is broken / adding Result builtin?● Warning: coroutine ‘...’ was never awaited● MultiError exception handling
– Make traceback objects instantiable / mutable / subclassable
– Mechanism to disable implicit chaining– More standard way to override exception printing?– More ergonomic MultiError handlers?
● Async generator cleanup / PEP 533Slides:tinyurl.com/trio-language-summit
![Page 22: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/22.jpg)
.throw() is broken :-(● bpo-29590: breaks stack introspection
(bad for profilers, debuggers, control-C handling)
● bpo-29587: no implicit exception chaining → trio is careful to never, ever use .throw()
![Page 23: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/23.jpg)
![Page 24: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/24.jpg)
If Resultwere built-in:
![Page 25: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/25.jpg)
Actual language issues● .throw() is broken / adding Result builtin?● Warning: coroutine ‘...’ was never awaited● MultiError exception handling
– Make traceback objects instantiable / mutable / subclassable
– Mechanism to disable implicit chaining– More standard way to override exception printing?– More ergonomic MultiError handlers?
● Async generator cleanup / PEP 533Slides:tinyurl.com/trio-language-summit
![Page 26: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/26.jpg)
f()g()await g()
![Page 27: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/27.jpg)
f()g()await g()
![Page 28: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/28.jpg)
async def test_f():
f()
async def test_g():
g()
![Page 29: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/29.jpg)
async def test_f():
f()
async def test_g():
g()
![Page 30: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/30.jpg)
>>> print(“hi”); f(1); print(“bye”)
hi
Warning: f() takes 0 positional arguments but 1 was given; function call skipped
bye
>>>
![Page 31: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/31.jpg)
The trio tutorial from 10,000 feet
![Page 32: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/32.jpg)
The trio tutorial from 10,000 feetIntro to async/await
![Page 33: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/33.jpg)
The trio tutorial from 10,000 feetIntro to async/await
Task spawning and nurseries
![Page 34: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/34.jpg)
The trio tutorial from 10,000 feetIntro to async/await
Task spawning and nurseries
Explaining Warning: coroutine ‘...’ was never awaited
![Page 35: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/35.jpg)
Are we just doomed?● In asyncio, g() calls are common :-(● Minimal proposal: add a global (or thread-
local) counter of times this warning fired, so test harness / trio main loop can detect the problem and blow up? (without having to monkeypatch warnings)
● More ambitious proposal →
![Page 36: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/36.jpg)
Straw proposal for 3.7● await x stays the same● await g(*args, **kwargs) → if hasattr(g, “__coroutine__”):
coro = g.__coroutine__(*args, **kwargs)
else:
coro = g.__call__(*args, **kwargs)
await coro
● Trio: use decorator or __future__ to make __call__ an error
● asyncio: use decorator to make __call__ return Task object; no more ensure_future
![Page 37: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/37.jpg)
Actual language issues● .throw() is broken / adding Result builtin?● Warning: coroutine ‘...’ was never awaited● MultiError exception handling
– Make traceback objects instantiable / mutable / subclassable
– Mechanism to disable implicit chaining– More standard way to override exception printing?– More ergonomic MultiError handlers?
● Async generator cleanup / PEP 533Slides:tinyurl.com/trio-language-summit
![Page 38: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/38.jpg)
main() │ ├─ f1() │ └─ f2() │ ├─ f2a() │ └─ f2b()
![Page 39: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/39.jpg)
main() │ ├─ f1() → KeyError │ └─ f2() │ ├─ f2a() → ValueError │ └─ f2b() → RuntimeError
![Page 40: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/40.jpg)
main() │ ├─ f1() → KeyError │ └─ f2() │ ├─ f2a() → ValueError │ └─ f2b() → RuntimeError
MultiError([ KeyError, MultiError([ ValueError, RuntimeError, ]),])
![Page 41: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/41.jpg)
main() │ ├─ f1() → KeyError │ └─ f2() │ ├─ f2a() → ValueError │ └─ f2b() → RuntimeError
MultiError([ KeyError, MultiError([ ValueError, RuntimeError, ]),])
Traceback (most recent call last): File "multierror.py", line 22, in <module> trio.run(main) File "multierror.py", line 6, in main nursery.spawn(f2)trio.MultiError: KeyError(), <MultiError: RuntimeError(), ValueError()>
Details of embedded exception 1:
Traceback (most recent call last): File "multierror.py", line 9, in f1 raise KeyError KeyError
Details of embedded exception 2:
Traceback (most recent call last): File "multierror.py", line 14, in f2 nursery.spawn(f2b) trio.MultiError: RuntimeError(), ValueError()
Details of embedded exception 1:
Traceback (most recent call last): File "multierror.py", line 17, in f2a raise ValueError ValueError
Details of embedded exception 2:
Traceback (most recent call last): File "multierror.py", line 20, in f2b raise RuntimeError RuntimeError
![Page 42: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/42.jpg)
Catching single exceptionsdef catch_block(exc): if isinstance(exc, (RuntimeError, KeyError)): return None else: return exc
with trio.MultiError.catch(catch_block): ...
Traceback (most recent call last): File "multierror-catch.py", line 28, in <module> trio.run(main) File "multierror-catch.py", line 12, in main nursery.spawn(f2) File "multierror-catch.py", line 20, in f2 nursery.spawn(f2b) File "multierror-catch.py", line 23, in f2a raise ValueErrorValueError
![Page 43: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/43.jpg)
Problems● PyPy has a special extension to specifically
allow mutating tracebacks w/o ctypes, b/c both jinja2 and trio need it
![Page 44: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/44.jpg)
Problems● PyPy has a special extension to specifically
allow mutating tracebacks w/o ctypes, b/c both jinja2 and trio need it
● Want to hide/annotate parts of traceback
![Page 45: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/45.jpg)
Traceback (most recent call last): File "multierror.py", line 22, in <module> trio.run(main) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_core/_run.py", line 1130, in run return result.unwrap() File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_core/_result.py", line 118, in unwrap raise self.error File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_core/_run.py", line 1230, in run_impl msg = task.coro.send(next_send) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_core/_run.py", line 747, in init return system_nursery.reap_and_unwrap(task) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_core/_run.py", line 286, in reap_and_unwrap return task.result.unwrap() File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_core/_result.py", line 118, in unwrap raise self.error File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_core/_run.py", line 1230, in run_impl msg = task.coro.send(next_send) File "multierror.py", line 6, in main nursery.spawn(f2) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_util.py", line 39, in __aexit__ await self._agen.asend(None) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/async_generator/impl.py", line 253, in asend return await self._do_it(self._it.send, value) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/async_generator/impl.py", line 269, in _do_it return await ANextIter(self._it, start_fn, *args) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/async_generator/impl.py", line 192, in send return self._invoke(self._it.send, value) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/async_generator/impl.py", line 199, in _invoke result = fn(*args) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_core/_run.py", line 213, in open_nursery await nursery._clean_up(pending_exc) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_core/_run.py", line 353, in _clean_up raise mexctrio.MultiError: KeyError(), <MultiError: RuntimeError(), ValueError()>
Details of embedded exception 1:
Traceback (most recent call last): File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_core/_run.py", line 1230, in run_impl msg = task.coro.send(next_send) File "multierror.py", line 9, in f1 raise KeyError KeyError
Details of embedded exception 2:
Traceback (most recent call last): File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_core/_run.py", line 1230, in run_impl msg = task.coro.send(next_send) File "multierror.py", line 14, in f2 nursery.spawn(f2b) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_util.py", line 39, in __aexit__ await self._agen.asend(None) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/async_generator/impl.py", line 253, in asend return await self._do_it(self._it.send, value) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/async_generator/impl.py", line 269, in _do_it return await ANextIter(self._it, start_fn, *args) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/async_generator/impl.py", line 192, in send return self._invoke(self._it.send, value) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/async_generator/impl.py", line 199, in _invoke result = fn(*args) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_core/_run.py", line 213, in open_nursery await nursery._clean_up(pending_exc) File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_core/_run.py", line 353, in _clean_up raise mexc trio.MultiError: RuntimeError(), ValueError()
Details of embedded exception 1:
Traceback (most recent call last): File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_core/_run.py", line 1230, in run_impl msg = task.coro.send(next_send) File "multierror.py", line 20, in f2b raise RuntimeError RuntimeError
Details of embedded exception 2:
Traceback (most recent call last): File "/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages/trio/_core/_run.py", line 1230, in run_impl msg = task.coro.send(next_send) File "multierror.py", line 17, in f2a raise ValueError ValueError
![Page 46: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/46.jpg)
Problems● PyPy has a special extension to specifically
allow mutating tracebacks w/o ctypes, b/c both jinja2 and trio need it
● Want to hide/annotate parts of traceback
![Page 47: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/47.jpg)
Problems● PyPy has a special extension to specifically
allow mutating tracebacks w/o ctypes, b/c both jinja2 and trio need it
● Want to hide/annotate parts of traceback● Implicit chaining corrupts context
information when re-raising :-(
![Page 48: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/48.jpg)
Problems● PyPy has a special extension to specifically
allow mutating tracebacks w/o ctypes, b/c both jinja2 and trio need it
● Want to hide/annotate parts of traceback● Implicit chaining corrupts context
information when re-raising :-(● pytest, IPython, … don’t know that
MultiErrors are special
![Page 49: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/49.jpg)
Problems● PyPy has a special extension to specifically
allow mutating tracebacks w/o ctypes, b/c both jinja2 and trio need it
● Want to hide/annotate parts of traceback● Implicit chaining corrupts context
information when re-raising :-(● pytest, IPython, … don’t know that
MultiErrors are special● MultiError.catch is kinda awkward
![Page 50: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/50.jpg)
Actual language issues● .throw() is broken / adding Result builtin?● Warning: coroutine ‘...’ was never awaited● MultiError exception handling
– Make traceback objects instantiable / mutable / subclassable
– Mechanism to disable implicit chaining– More standard way to override exception printing?– More ergonomic MultiError handlers?
● Async generator cleanup / PEP 533Slides:tinyurl.com/trio-language-summit
![Page 51: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/51.jpg)
![Page 52: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/52.jpg)
![Page 53: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/53.jpg)
PEP 533● Proposes to add __(a)close__ methods
to iterator protocol● Basic idea: (async) for will call __(a)close__ no matter how it exits (i.e.: adding little with flavor to for loops)
● There are a bunch of details + transition plan in the PEP
● Is it a good idea? Dunno. But so far the main alternative proposal is “never use with/try/finally in (async) generators”...
![Page 54: May 17, 2017 Python Language Summit - Nathaniel J. Smithnjs/misc/trio-language-summit-2017.pdf · Trio a report from the wilds of async Nathaniel J. Smith May 17, 2017 Python Language](https://reader030.vdocument.in/reader030/viewer/2022041014/5ec4d8ed26e62b306404ba0a/html5/thumbnails/54.jpg)
Thanks for listening!● .throw() is broken / adding Result builtin?● Warning: coroutine ‘...’ was never awaited● MultiError exception handling
– Make traceback objects instantiable / mutable / subclassable
– Mechanism to disable implicit chaining– More standard way to override exception printing?– More ergonomic MultiError handlers?
● Async generator cleanupSlides:tinyurl.com/trio-language-summit