question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A way to collect results upon exiting task group

See original GitHub issue

In asyncio, there’s await asyncio.gather(..a..lot..of..tasks).

Is it possible to somehow emulate this with anyio?

I’m thinking of something like this maybe:

async with create_task_group() as tg:
    await tg.spawn(t1)
    await tg.spawn(t2)

print(tg.results)  # t1_res, t2_res

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:26 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
Tinchecommented, Nov 22, 2021

It’s well within your rights to wontfix this, but I will chip in my $0.02 and say when I found out anyio/trio don’t have good gather ergonomics my interest waned pretty significantly. In other words, I find gather in asyncio very, very good. Which is a little unfortunate because anyio/trio cancellation scopes are so awesome.

3reactions
smurfixcommented, Sep 18, 2020
try:
    from anyio import create_queue
except ImportError:
    from anyio import create_memory_object_stream as _cmos

    class Queue:
        def __init__(self, length=0):
            self._s, self._r = _cmos(length)

        def put(self, x):
            return self._s.send(x)

        def get(self):
            return self._r.receive()

        def qsize(self):
            return len(self._s._state.buffer)  # ugh

        def empty(self):
            return not len(self._s._state.buffer)  # ugh

        def __aiter__(self):
            return self

        def __anext__(self):
            return self._r.__anext__()

    def create_queue(length=0):
        return Queue(length)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding Swift Task Groups With Example - Swift Senpai
A task group can exit by either returning a value, returning void (non-value-returning), or throwing an error. Now that you have learned how...
Read more >
Task groups in Azure Pipelines and TFS (classic)
A task group allows you to encapsulate a sequence of tasks, already defined in a build or a release pipeline, into a single...
Read more >
Accept the first Task to complete - Using Swift - Swift Forums
I've been searching without luck for a method or pattern to accept the first member of a TaskGroup (or some other collection of...
Read more >
How to create a task group and add tasks to it
Swift's task groups are collections of tasks that work together to produce a single result. Each task inside the group must return the...
Read more >
Running tasks in parallel with Swift Concurrency's task groups
As we iterate over the group's results, a failed task also counts as a result. However, when the group's next() function is called...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found