Utility classes and functions for AnyIO
Project description
anyioutils
Utility classes and functions for AnyIO.
Task
task = anyioutils.create_task(my_async_func(), task_group)
behaves the same as task = asyncio.create_task(my_async_func())
except that an existing task_group
has to be passed for the task to be launched in the background.
You can also use task = anyioutils.Task(my_async_func())
and then launch the task
with task_group.start_soon(task.wait)
, and/or await it with result = await task.wait()
.
from anyioutils import CancelledError, Task, create_task
from anyio import create_task_group, run, sleep
async def foo():
return 1
async def bar():
await sleep(float("inf"))
async def main():
async with create_task_group() as tg:
task = Task(foo())
assert await task.wait() == 1
try:
async with create_task_group() as tg:
task = create_task(bar(), tg)
await sleep(0.1)
task.cancel()
except BaseExceptionGroup as exc_group:
assert len(exc_group.exceptions) == 1
assert type(exc_group.exceptions[0]) == CancelledError
run(main)
Future
anyioutils.Future
behaves the same as asyncio.Future
except that:
- you cannot directly await an
anyioutils.Future
object, but through its.wait()
method (unlike anasyncio.Future
, but like anasyncio.Event
), - cancelling an
anyioutils.Future
doesn't raise ananyio.get_cancelled_exc_class()
, but ananyioutils.CancelledError
.
from anyioutils import CancelledError, Future
from anyio import create_task_group, run
async def set_result(future):
future.set_result("done")
async def cancel(future):
future.cancel()
async def main():
async with create_task_group() as tg:
future0 = Future()
tg.start_soon(set_result, future0)
assert await future0.wait() == "done"
future1 = Future()
tg.start_soon(cancel, future1)
try:
await future1.wait()
except CancelledError:
assert future1.cancelled()
run(main)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file anyioutils-0.4.7.tar.gz
.
File metadata
- Download URL: anyioutils-0.4.7.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aeb6806f69b13a91fdede02b61a0194fd637f0aadf23e813b23a448973a17670 |
|
MD5 | c5e2779cf5935566da09dced0234e74b |
|
BLAKE2b-256 | 7114deddd484fc3af9378254e37af315cc689013ee285e6d9eb694ed1fbec04e |
Provenance
The following attestation bundles were made for anyioutils-0.4.7.tar.gz
:
- Repository: davidbrochart/anyioutils
- Workflow: publish.yml
-
Statement type: https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
anyioutils-0.4.7.tar.gz
- Subject digest:
aeb6806f69b13a91fdede02b61a0194fd637f0aadf23e813b23a448973a17670
- Transparency log index: 147537232
- Transparency log integration time:
- Predicate type:
File details
Details for the file anyioutils-0.4.7-py3-none-any.whl
.
File metadata
- Download URL: anyioutils-0.4.7-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f9514c5f727f4c9eeb5267dc2268bab728e33803efdfe01069653dce217d701 |
|
MD5 | 9cdf53ded37053dd00b4c5be930a756f |
|
BLAKE2b-256 | 5b822e05d788e67dd6ce848c8f5ec90f36001bcefe01ead5e63001b238952a79 |
Provenance
The following attestation bundles were made for anyioutils-0.4.7-py3-none-any.whl
:
- Repository: davidbrochart/anyioutils
- Workflow: publish.yml
-
Statement type: https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
anyioutils-0.4.7-py3-none-any.whl
- Subject digest:
2f9514c5f727f4c9eeb5267dc2268bab728e33803efdfe01069653dce217d701
- Transparency log index: 147537235
- Transparency log integration time:
- Predicate type: