High level asynchronous concurrency and networking framework that works on top of either trio or asyncio
Added support for the Python 3.12 walk_up
keyword argument in anyio.Path.relative_to()
(PR by Colin Taylor)
Fixed passing total_tokens
to anyio.CapacityLimiter()
as a keyword argument not working on the trio
backend (#515)
Fixed Process.aclose()
not performing the minimum level of necessary cleanup when cancelled. Previously:
Process.aclose()
could leak an orphan processrun_process()
could very briefly leak an orphan process.Process.aclose()
or run_process()
on Trio could leave standard streams unclosed(PR by Ganden Schaffner)
Fixed Process.stdin.aclose()
, Process.stdout.aclose()
, and Process.stderr.aclose()
not including a checkpoint on asyncio (PR by Ganden Schaffner)
Fixed documentation on how to provide your own typed attributes
Add support for byte
-based paths in connect_unix
, create_unix_listeners
, create_unix_datagram_socket
, and create_connected_unix_datagram_socket
. (PR by Lura Skye)
Enabled the Event
and CapacityLimiter
classes to be instantiated outside an event loop thread
Broadly improved/fixed the type annotations. Among other things, many functions and methods that take variadic positional arguments now make use of PEP 646 TypeVarTuple
to allow the positional arguments to be validated by static type checkers. These changes affected numerous methods and functions, including:
anyio.run()
TaskGroup.start_soon()
anyio.from_thread.run()
anyio.from_thread.run_sync()
anyio.to_thread.run_sync()
anyio.to_process.run_sync()
BlockingPortal.call()
BlockingPortal.start_task_soon()
BlockingPortal.start_task()
(also resolves #560)
Fixed various type annotations of anyio.Path
to match Typeshed:
anyio.Path.__lt__()
anyio.Path.__le__()
anyio.Path.__gt__()
anyio.Path.__ge__()
anyio.Path.__truediv__()
anyio.Path.__rtruediv__()
anyio.Path.hardlink_to()
anyio.Path.samefile()
anyio.Path.symlink_to()
anyio.Path.with_segments()
(PR by Ganden Schaffner)
Fixed adjusting the total number of tokens in a CapacityLimiter
on asyncio failing to wake up tasks waiting to acquire the limiter in certain edge cases (fixed with help from Egor Blagov)
Fixed loop_factory
and use_uvloop
options not being used on the asyncio backend (#643)
Fixed cancellation propagating on asyncio from a task group to child tasks if the task hosting the task group is in a shielded cancel scope (#642)
trio.to_thread.run_sync()
using the abandon_on_cancel
keyword argument instead of cancellable
cancellable
argument in anyio.to_thread.run_sync()
to abandon_on_cancel
(and deprecated the old parameter name)anyio.from_thread.check_cancelled()
ResourceGuard
class in the public API (#627)RuntimeError: Runner is closed
when running higher-scoped async generator fixtures in some cases (#619)asyncio
and trio
where reraising a cancellation exception in an except*
block would incorrectly bubble out of its cancel scope (#634)ExceptionGroup
class with the PEP 654 BaseExceptionGroup
and ExceptionGroup
ExceptionGroup
(or BaseExceptionGroup
if one or more BaseException
were included)TaskGroup
always hits a yield point, regardless of whether there are running child tasks to be waited onanyio.Path.relative_to()
and anyio.Path.is_relative_to()
to only accept one argument, as passing multiple arguments is deprecated as of Python 3.12@asyncio.coroutine
)policy
option on the asyncio
backend was changed to loop_factory
to accommodate asyncio.Runner
anyio.run()
to use asyncio.Runner
(or a back-ported version of it on Pythons older than 3.11) on the asyncio
backendanyio.Path.is_junction()
and anyio.Path.walk()
methodscreate_unix_datagram_socket
and create_connected_unix_datagram_socket
to create UNIX datagram sockets (PR by Jean Hominal)from_thread.run
and from_thread.run_sync
not setting sniffio on asyncio. As a result:
from_thread.run_sync
failing when used to call sniffio-dependent functions on asynciofrom_thread.run
failing when used to call sniffio-dependent functions on asyncio from a thread running trio or curiofrom_thread.start_blocking_portal(backend="asyncio")
in a thread running trio or curio (PR by Ganden Schaffner)item_type
argument of create_memory_object_stream
was deprecated. To indicate the item type handled by the stream, use create_memory_object_stream[T_Item]()
instead. Type checking should no longer fail when annotating memory object streams with uninstantiable item types (PR by Ganden Schaffner)CancelScope.cancelled_caught
property which tells users if the cancel scope suppressed a cancellation exceptionfail_after()
raising an unwarranted TimeoutError
when the cancel scope was cancelled before reaching its deadlineMemoryObjectReceiveStream.receive()
causing the receiving task on asyncio to remain in a cancelled state if the operation was cancelled after an item was queued to be received by the task (but before the task could actually receive the item)TaskGroup.start()
on asyncio not responding to cancellation from the outsideBlockingPortal
not notifying synchronous listeners (concurrent.futures.wait()
) when they're cancelledEvent.wait()
on asyncio in the case where the event was not yet setanyio.to_process()
being "lost" as unusable to the process pool when processes that have idled over 5 minutes are pruned at part of the to_process.run_sync()
call, leading to increased memory consumption (PR by Anael Gorfinkel)Changes since 4.0.0rc1:
TaskGroup.start_soon()
to accept any awaitables (already in v3.7.0 but was missing from 4.0.0rc1)CancelScope
to also consider the cancellation count (in addition to the cancel message) on asyncio to determine if a cancellation exception should be swallowed on scope exit, to combat issues where third party libraries catch the CancelledError
and raise another, thus erasing the original cancel messageTLSListener.handle_handshake_error()
on asyncio to log "NoneType: None"
instead of the error (PR by Ganden Schaffner)item_type
argument to create_memory_object_stream()
(but using it raises a deprecation warning and does nothing with regards to the static types of the returned streams)anyio.to_process()
being "lost" as unusable to the process pool when processes that have idled over 5 minutes are pruned at part of the to_process.run_sync()
call, leading to increased memory consumption (PR by Anael Gorfinkel)