Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved cancellation semantics #496

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/tasks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,21 @@ host task that will be copied, but the context of the task that calls
support for this only landed in v3.7.

.. _context: https://docs.python.org/3/library/contextvars.html

Differences with asyncio.TaskGroup
----------------------------------

The :class:`asyncio.TaskGroup` class, added in Python 3.11, is very similar in design to
the AnyIO :class:`~TaskGroup` class. The asyncio counterpart has some important
differences in its semantics, however:

* Tasks are spawned solely through :meth:`~asyncio.TaskGroup.create_task`; there is no
``start()`` or ``start_soon()`` method
* The :meth:`~asyncio.TaskGroup.create_task` method returns a task object which can be
awaited on (or cancelled)
* Tasks can only be cancelled individually (there is no ``cancel()`` method or similar
in the task group)
* When a task is cancelled before its coroutine has started running, it will not get a
chance to handle the cancellation exception
* New tasks cannot be started after an exception in one of the tasks has triggered a
shutdown
11 changes: 11 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.

- **BACKWARDS INCOMPATIBLE** Replaced AnyIO's own ``ExceptionGroup`` class with the PEP
654 ``BaseExceptionGroup`` and ``ExceptionGroup``
- **BACKWARDS INCOMPATIBLE** Changes to cancellation semantics:

- Any exceptions raising out of a task groups are now nested inside an
``ExceptionGroup`` (or ``BaseExceptionGroup`` if one or more ``BaseException`` were
included), except when all the exceptions are cancellation exceptions. In that case,
a single cancellation exception is raised instead.
- ``CancelScope`` now un-cancels its host task on Python 3.11 + asyncio when
appropriate, for compatibility with ``asyncio.timeout`` and other context managers
that swallow exceptions
- Bumped minimum version of trio to v0.22
- Added ``create_unix_datagram_socket`` and ``create_connected_unix_datagram_socket`` to
create UNIX datagram sockets (PR by Jean Hominal)
Expand Down Expand Up @@ -42,6 +51,8 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
the event loop to be closed
- Fixed ``current_effective_deadline()`` not returning ``-inf`` on asyncio when the
currently active cancel scope has been cancelled (PR by Ganden Schaffner)
- Fixed task group not raising a cancellation exception on asyncio at exit if no child
tasks were spawned and an outer cancellation scope had been cancelled before

**3.6.1**

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classifiers = [
]
requires-python = ">= 3.7"
dependencies = [
"exceptiongroup; python_version < '3.11'",
"exceptiongroup >= 1.0.2; python_version < '3.11'",
"idna >= 2.8",
"sniffio >= 1.1",
"typing_extensions; python_version < '3.8'",
Expand Down
Loading