danh
(Dan Halbert)
January 5, 2022, 2:54pm
1
Now that PEP 654 (ExceptionGroups and except*) is close to done (thank you Irit!), what are the next steps for asyncio? My understanding is that PEP 654 is a blocker for TaskGroup
. Will there be a PEP for TaskGroup
, or is it only a PR?
I personally would like to see mainly the following:
TaskGroup
An addition of a function similar to gather()
that cancels the other tasks when one task raises an exception. This was originally a bug report against gather()
, and was rejected.
I speak as a CircuitPython core developer. except*
may not get into MicroPython (our primary source for core language features) any time soon. Nevertheless, we’d like to provide additions to our own asyncio
that mimic upcoming CPython asyncio features, so we’d very interested in upcoming specs.
Thank you,
Dan
3 Likes
danh
(Dan Halbert)
February 16, 2022, 2:21pm
2
Taskgroups are now being added:
python:main
← gvanrossum:taskgroups
opened 02:35AM - 11 Feb 22 UTC
This is EdgeDB's TaskGroup class, adapted for Python 3.11.
In the individual … commits you can see how I evolved this from the version in EdgeDB.
Here's a to-do list:
- [x] Figure out why in `test_taskgroup_14` I get a nested `ExceptionGroup`, while the original got a flat MultiError.
- [x] Fix the test framework's complaint about the event loop policy being changed.
- [x] **Design question:** Do we need `TaskGroupError`? Implementing it correctly is awkward. We could just raise `BaseExceptionGroup`.
- ~If we decide to keep it, we need to fix it to do the hack where it inherits from `BaseException` iff at least one of the exceptions does. We also need to override `derive()`.~
- [x] Add tests for handling `BaseException`, ~`KeyboardInterrupt` and `SystemExit`~.
- [x] ~Make `test_taskgroup_21` work? (It wasn't working in EdgeDB either, so it was crudely disabled.)~
- [x] Add a public API to `tasks.py` to replace `__cancel_requested__`, and get rid of the monkey-patching.
- [x] **Design question:** Should we allow creating new tasks while `__aexit__()` is already waiting?
- [ ] Add a test showing the need for the `.uncancel()` call in `__aexit__()` (currently on line 97). Dropping that line does not cause any tests to fail.
- [ ] Ensure the taskgroup tests are run with the C and Python Task implementations.
- [ ] Rename tests to have meaningful names.
- [ ] I have a few ideas for minor cleanups that I will do later.
- [x] What should we do with the copyright header? @1st1.
- [x] Create a bpo issue.
- [x] Add a NEWS blurb.
- [ ] Documentation and What's New entry (in a separate PR, probably).
I also learned a few things about the ergonomics of `ExceptionGroup`:
- The `BaseException` hacks are clever but awkward to replicate in a subclass.
- The `str()` of an EG is rather sparse (Yury's version adds the number of sub-exceptions and their types).
- Yury's version also has a convenience method that returns the set of sub-exception types.
- Unsure about the nesting issue (see above).
CC: @iritkatriel, @1st1
Co-authored-by: Yury Selivanov <yury@edgedb.com>
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
https://bugs.python.org/issue46752
https://bugs.python.org/issue46752
A canceling version of gather()
would still be nice too.
1 Like
achimnol
(Joongi Kim)
February 24, 2022, 2:56pm
3
I have filed two bpo issues:
I’d like to hear suggestions and feedbacks!