malinoff / aionursery Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
This can happen if an await is used in the context manager's scope (see the updated tests in my PR).
Following behaviour is specified In README:
Any unhandled exceptions are re-raised inside the parent task. If there are multiple exceptions, then they’re collected up into a single MultiError exception.
That is not true. Actually aionursery will raise MultiError even if there is only one exception:
if self._pending_excs:
raise MultiError(self._pending_excs)
I suggest to add appropriate condition to aionursery source code:
if len(self._pending_excs) == 1:
raise self._pending_excs[0]
if self._pending_excs:
raise MultiError(self._pending_excs)
It will simplify exception handling.
To reproduce:
# coding: utf-8
import aionursery
import asyncio
async def foo(i):
if i == 2:
1/0
if i == 1:
print("1 sleeping ...")
await asyncio.sleep(0.1)
print("1 OK")
print(i)
async def main():
try:
async with aionursery.Nursery() as start_nursery:
for i in range(10):
start_nursery.start_soon(foo(i))
except aionursery.MultiError as exc:
print(f"MultiError: {exc}")
asyncio.run(main())
Output:
0
1 sleeping ...
3
4
5
6
7
8
9
MultiError: [ZeroDivisionError('division by zero')]
Details of embedded exception 0:
Traceback (most recent call last):
File "<input>", line 8, in foo
ZeroDivisionError: division by zero
print("1 OK")
is never reach.
/usr/local/lib/python3.7/site-packages/aionursery.py:61: PendingDeprecationWarning: Task.current_task() is deprecated, use asyncio.current_task() instead
self._parent_task = asyncio.Task.current_task(self._loop)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.