Skip to content

agronholm/aionursery

Repository files navigation

Build Status

Code Coverage

Warning

This library is is no longer being maintained. Use anyio instead.

This library implements a task supervisor concept for asyncio in the likeness of trio's nurseries nurseries. It was inspired by a blog entry by Nathaniel J. Smith.

It attempts to follow the same design principles as the original:

  • It will make sure that all the task spawned from the nursery will have finished one way or the other be left running when the async with block is exited
  • If any of the spawned tasks, or the host task running the async with block, raises an exception, all the tasks are cancelled
  • If more than one exception is raised by the tasks, a aionursery.MultiError is raised which contains all the raised exceptions in the exceptions attribute

Here is how to spawn background tasks with a nursery:

from asyncio import get_event_loop

from aionursery import Nursery


async def main():
    async with Nursery() as nursery:
        nursery.start_soon(your_coroutine_function, arg1, arg2)
        nursery.start_soon(another_coroutine_function, arg1, arg2)

get_event_loop().run_until_complete(main())

About

Trio-like nurseries for asyncio

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages