3 ms·
To save others the search regarding a nursery: https://trio.readthedocs.io/en/stable/tutorial.html#okay-let-s-see-something-cool-already https://trio.readthedoc
by nerdwaller 6y ago
To save others the search regarding a nursery: https://trio.readthedocs.io/en/stable/tutorial.html#okay-let-s-see-something-cool-already 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?
- j88439h84 6y agoI'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-go-statement-considered-harmful/ 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.
- nerdwaller 6y agoFair enough, the ensure_future() vs create_task() has confused me more than once. It would have been nice if there was a different namespace for the lower level API. Even so, the docs aren’t even clear on when which of the two is appropriate: https://docs.python.org/3/library/asyncio-task.html#asyncio... https://docs.python.org/3/library/asyncio-task.html#asyncio..... https://docs.python.org/3/library/asyncio-future.html#asynci.. https://docs.python.org/3/library/asyncio-future.html#asynci....
- naasking 6y agoAn interesting idea, essentially Trio restructures concurrent code to more closely resemble parallel code, which innately has the property that the concurrency is not observable, ie. the black box property. It's a little more general than strict parallel code though because task spawning is reified as a first class value via which the program can spawn new tasks. I'm not sure it's totally novel though. For instance, C# has AsParallel() extensions which let you run collection operations in parallel (similar functions in Haskell too). It has the same black box behaviour described by the article, and there's an equivalence between direct control flow in code and indirect control flow reified as a data structure, ie. Haskell's case that lazy evaluation and lists are the only control flow construct you need. Still, it's an interesting imperative incarnation of the idea!