News for hackers. Stuff that matters.
Re:Free-threaded CPython is ready to experiment with by hot_gril on Friday July 12, 2024 @07:13PM (#40950319)
Basically true in JS too. You're not supposed to do blocking calls in async code. You also can't "await" an async call inside a non-async func, though you could fire-and-forget it.

Right, but how often does a Python program have complex shared state across threads, rather than some simple fan-out-fan-in, and also need to take advantage of multiple cores?

Re:Free-threaded CPython is ready to experiment with by nilamo on Friday July 12, 2024 @07:56PM (#40950548)
The primary thing that tripped me up about async/await, specifically only in Python, is that the called function does not begin running until you await it. Before that moment, it's just an unstarted generator.

To make background jobs, I've used the class-based version to start a thread, then the magic method that's called on await simply joins the thread. Which is a lot of boilerplate to get a little closer to how async works in (at least) js and c#.

Re:Free-threaded CPython is ready to experiment with by LegionMammal978 on Friday July 12, 2024 @08:28PM (#40950721)
Rust's version of async/await is the same in that respect, where futures don't do anything until you poll them (e.g., by awaiting them): if you want something to just start right away, you have to call out to the executor you're using, and get it to spawn a new task for it.

Though to be fair, people complain about this in Rust as well. I can't comment much on it myself, since I haven't had any need for concurrent workloads that Rayon (a basic thread-pool library with work stealing) can't handle.

Re:Free-threaded CPython is ready to experiment with by pests on Friday July 12, 2024 @10:01PM (#40951175)
That is a common split in language design decisions. I think the argument for the python-style where you have to drive it to begin is more useful as you can always just start it immediately but also let's you delay computation or pass it around similar to a Haskell thunk.
Re:Free-threaded CPython is ready to experiment with by kristjansson on Saturday July 13, 2024 @02:13AM (#40952188)
There is also https://docs.python.org/3/library/asyncio-task.html#eager-ta... if you want your task to start on creation.