Live data from Hacker News

Waiting in Asyncio

hynek.me

11–20 of 31 posts

Re: Waiting in Asyncio

#12

Trio is a much simpler design that's just as powerful as `asyncio`. It has exactly one way to wait for a task: await it. https://trio.readthedocs.io/ For a group of tasks, use a nursery. Edit: correction

To save others the search regarding a nursery: https://trio.readthedocs.io/en/stable/tutorial.html#okay-let...

I don’t see much more useful here than understanding the asyncio primitives and available synchronization abstractions, just a different API mostly overlapping the same need

To be clear, trio also has more than one way to wait for a task - any await is the same (e.g. `await trio.sleep(N)` (e.g. `await asyncio.sleep(N)`). I think maybe you’re getting at waiting for a group of tasks?

Re: Waiting in Asyncio

#13
post #2

All these subtleties and gotchas signify, to me, a shit implementation and a fragmented interface. The exact opposite of the Zen of python.

What would be the essence of that zen? A ridiculously slow interpreter? Littering your directories with .pyc files? The world's worst package and dependency management?

Don't get me wrong, python is a lovely language when the universe aligns perfectly. But buggy libraries with fragmented interfaces are everywhere in the python community, and any zen that could have been had by pythons expressiveness gets obliterated by the various other warts and faults of the ecosystem. It's just a tool, not a form of enlightenment.

Re: Waiting in Asyncio

#14

Trio is a much simpler design that's just as powerful as `asyncio`. It has exactly one way to wait for a task: await it. https://trio.readthedocs.io/ For a group of tasks, use a nursery. Edit: correction

To save others the search regarding a nursery: https://trio.readthedocs.io/en/stable/tutorial.html#okay-let... I don’t see much more useful here than understanding the asyncio primitives and available synchronization abstractions, just a different API mostly overlapping the same need To be clear, trio also has more than one way to wait for a task - any await is the same (e.g. `await trio.sleep(N)` (e.g. `await asynci…

I'm on mobile so cant type a long response but IME its quite different in terms of ease of use, complexity, and correctness.

For a theoretical take see

https://vorpus.org/blog/notes-on-structured-concurrency-or-g...

To be precise, to wait for a task its actually just await. Theres no ensure_future etc. Trio doesn't have the concept of futures or promises at all, and await f() is treated as a single piece of syntax, so in practice it doesn't have "awaitables" either.

Re: Waiting in Asyncio

#15
post #2

All these subtleties and gotchas signify, to me, a shit implementation and a fragmented interface. The exact opposite of the Zen of python.

What would be the essence of that zen? A ridiculously slow interpreter? Littering your directories with .pyc files? The world's worst package and dependency management? Don't get me wrong, python is a lovely language when the universe aligns perfectly. But buggy libraries with fragmented interfaces are everywhere in the python community, and any zen that could have been had by pythons expressiveness gets obliterated…

There is a document called "the zen of python".

Re: Waiting in Asyncio

#16

Trio is a much simpler design that's just as powerful as `asyncio`. It has exactly one way to wait for a task: await it. https://trio.readthedocs.io/ For a group of tasks, use a nursery. Edit: correction

Structured concurrency is why you should use Trio.

What do you get? For starters, Ctrl-C/KeyboardInterrupt just works. By restricting the design space, you end up with much more intuitive designs.

Obligatory Structured Concurrency essay link: https://vorpus.org/blog/notes-on-structured-concurrency-or-g...

I recommend giving it a read.

Re: Waiting in Asyncio

#17
post #2

All these subtleties and gotchas signify, to me, a shit implementation and a fragmented interface. The exact opposite of the Zen of python.

A more charitable view is that they signify an API that evolved from callback-based APIs like Twisted over many years and made nicer APIs like curio or trio only possible (whose features/insights slowly feed back into asyncio but backward compat keeps the warts around).

Re: Waiting in Asyncio

#18
- wouldn't it be nice if you could figure out if a function/method could block?

- What's a good strategy to migrate a larger python codebase towards asyncio ? (Haven't found any)

Re: Waiting in Asyncio

#20
post #2

All these subtleties and gotchas signify, to me, a shit implementation and a fragmented interface. The exact opposite of the Zen of python.

What would be the essence of that zen? A ridiculously slow interpreter? Littering your directories with .pyc files? The world's worst package and dependency management? Don't get me wrong, python is a lovely language when the universe aligns perfectly. But buggy libraries with fragmented interfaces are everywhere in the python community, and any zen that could have been had by pythons expressiveness gets obliterated…

Zen merely means meditation. It’s a practice, not a state of being or enlightenment.

I think the confusion comes about because many people use Tao and zen interchangeably. The Tao is supposed to represent a total understanding of the underlying universal principals, which can be seen as a form of enlightenment.

However Zen is not that.

The zen of python would represent a way to meditate while coding in python. Though I will admit the actual document reads more like a Tao, and it was originally called “the way of Python” (Tao also translates as the way).

https://www.python.org/dev/peps/pep-0020/

Post reply on HN