Traio

Latest version: v0.5.2

Safety actively analyzes 619599 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 2

0.5.2

- Protect task against bubbling when adding a done callback to it (same as awaiting it)
- when cancelling a scope, await all tasks in parallel (instead of one by one)
- add documentation and tests around `run_in_executor`

0.5.1

A task by default is awaited, which means the scope will wait for it to finish during finalisation stage, before exiting.

It is now possible (thanks ll1ks!) to mark some tasks as not awaited if you want a task running, but not so essential that it should prevent cancellation. Typically, a background job which has no meaning alone.

This is backward compatible as by default, like before, tasks are awaited.

0.5.0

In this new release, we modified slightly how `Scope` teardown is performed, and it is now easier and simpler to use:

- As a context manager
python
async with Scope(timeout=10) as scope:
scope << do_something()
At this point you are guaranteed that task created on the scope are finished, or cancelled and awaited.


- As a long living scope which will be cancelled by API
python
async def main():
scope = Scope()
scope.spawn(server_coro(), master=True)
await scope


- Or you can also mark a scope as `finalized`, in which case it will automatically be terminated when the last task is done
python
async def main():
scope = Scope()
scope << will_last_some_time()

Mark scope a finalized and wait for its task to terminate
scope.finalize()
await scope


Note that `join` function as been removed in favor if this new mechanism. The same way, `Scope.set_current` is now internal `Scope._set_current` and should not be used externally unless you really know what you are doing.

0.4.1

Before this release, doing something like this:

python
async with Scope(timeout=1):
await asyncio.sleep(10)


Would have blocked for 10 second, the timeout not being enforced. Same problem if the Scope was cancelled.
Now timeout and cancellation while the context code is blocked is handled properly!

0.4.0

I didn't like much the `Nursery` name in itself. In the end it's all about managing a scope, and although Trio just makes the distinction between Nursery and Cancel scope, here it seemed a bit too much.

So now you call:
python
async with Scope() as s:
s.spawn(coro())


Other things are identical, with the addition of a new class method `Scope.get_current()` which will return the current scope in (hopefully) most of the cases, especially if running in a task spawned by a scope!

0.3.1

Changes:
- Nursery now inherits from Future; we don't need the _done internal future anymore!
- There is no more start function, which was overkill and annoying when used without context manager
- No more internal state. Use Future state to know how it went
- Most of the logs are now debugs
- We can now `fork` a Nursery! just use the child Nursery as usual, but:
- child nursery can be launched with the same parameters as a task
- child nursery will be cancelled with parent (yeah!)
- but an error in child will not cancel the parent directly
- `Nursery.set_debug` allows to enable internal logging
- Implementation of the `<<` operator as en equivalent of `start_soon`
- add join(forever=True) capability to get a never auto-cancelling Nursery
- add a provisional `Nursery.get_tasks` method to retrieve all tasks of a scope
- improved documentation

If you are working with this package already since 0.2, this will not change much.

Just be careful, next release will rename `Nursery` into `Scope` and `start_soon` into `spawn`!

Page 1 of 2

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.