Live data from Hacker News

Python has had async for 10 years – why isn't it more popular?

tonybaloney.github.io

201–210 of 305 posts

Re: Python has had async for 10 years – why isn't it more popular?

#201

Earlier quoted context omitted.

asyncio has been designed to be as "plug and play" as it gets. I'd discourage it, but one could create async loops wherever one would need them, one separate thread per loop, and adapt the code base in a more granular fashion. Blocking through the GIL will persist, though. For any new app that is mostly IO constraint I'd still encourage the use of asyncio from the beginning.

I remember back when the “Pythonic” philosophy was to make the language accessible. It’s clear that Dr. Frankenstein has been at large and managed to get his hands on Python’s corpse.

I don’t think that’s fair. Yeah, there is a lot to learn and keep track of. At the same time, it’s an inherently complex problem. From one POV, and async Python program looks a lot like a cooperative multitasking operating system, but with functions instead of processes. It was a lot harder to write well-behaved programs on classic Mac OS than it was on a Commodore 64, but that Mac app was doing an awful lot more than the C64 program was. You couldn’t write them the same way and expect good results, but instead had to go about it a totally different way. It didn’t mean the Mac way was bad, just that it had a lot more inherent complexity.

Re: Python has had async for 10 years – why isn't it more popular?

#204

Earlier quoted context omitted.

First, I don’t mean to criticize anything or anyone. People value such things subjectively, but for me the async/sync split does no good. Goroutines feel like old-school, threaded code to me. I spawn a goroutine and interact with other “threads” through well defined IPC. I can’t tell if I’m spawning a green thread or a “real” system thread. C#’s async/await is different IMO and I prefer the other model. I think the a…

Wouldn't the old school style be more like rust async? Simple structs that you poll whenever you need to explicitly. No magic code that looks synchronous but isn't.

No, Rust async is new-school colored-functions concurrency.

Re: Python has had async for 10 years – why isn't it more popular?

#205
post #46

I used to keep plugging Unyielding [1] vs. What Color Is Your Function [2] as the right matrix to view these issues within. But then Notes on structured concurrency [3] was written and I just point to that these days. But, to sum it all up for those who want to talk here, there are several ways to look at concurrency but only one that matters. Is my program correct? How long will it take to make my program correct? S…

I'll second the plug for structured concurrency (and specifically the Trio [1] library that the author wrote. [1] https://github.com/python-trio/trio

If I ever want to use async in python again i'm going with Trio.

Re: Python has had async for 10 years – why isn't it more popular?

#206
post #149

Earlier quoted context omitted.

I think Python async is pretty cool - much nicer than threading or multiprocessing - yet has a few annoying rough edges like you say. Some specific issues I run into every time: Function colours can get pretty verbose when you want to write functional wrappers. You can end up writing nearly the exact same code twice because one needs to be async to handle an async function argument, even if the real functionality of…

I think the general idea of function colors has some merit - when done right, it's a crude way to communicate information about a function's expected runtime in a way that can be enforced by the environment: A sync function is expected to run short enough that it's not user-perceptible, whereas an async function can run for an arbitrary amount of time. In "exchange", you get tools to manage the async function while i…

> Maybe a useful approach for a language would be to make "colors" a first-class part of the type system and support them in generics, etc.

This is what languages with higher-kinded types do and it's glorious. In Scala you write your code in terms of a generic monad and then you can reuse it for sync or async.

Re: Python has had async for 10 years – why isn't it more popular?

#207
post #52

Earlier quoted context omitted.

> Code that looks synchronous, but is really async, has funny failure modes and idiosyncracies But this appears to be describing languages with green threads, rather than languages that make async explicit.

Without the "async" keyword, you can still write async code. It looks totally different because you have to control the state machine of task scheduling. Green threads are a step further than the async keyword because they have none of the function coloring stuff. You may think of use of an async keyword as explicit async code but that is very much not the case. If you want to see async code without the keyword, most…

> Green threads are a step further than the async keyword because they have none of the function coloring stuff.

I would say that green threads still have "function coloring stuff", we just decided that every function will be async-colored.

Now, what happens if you try to cross an FFI-border and try to call a function that knows nothing about your green-thread runtime is an entirely different story...

Re: Python has had async for 10 years – why isn't it more popular?

#208
post #79

The author gets close to what I think the root problem is, but doesn't call it out. The truth is that in python, async was too little, too late. By the time it was introduced, most people who actually needed to do lots of io concurrently had their own workarounds (forking, etc) and people who didn't actually need it had found out how to get by without it (multiprocessing etc). Meanwhile, go showed us what good green…

You make a very good case for why python's async isn't more prevalent, but I think this is not painting the full image. Taking a general case, let's say a forum, in order to render a thread one needs to search for all posts from that thread, then get all the extra data needed for rendering and finally send the rendered output to the client. In the "regular" way of doing this, one will compose a query, that will filte…

Why do you think that all of that extra compute work would be better?

Re: Python has had async for 10 years – why isn't it more popular?

#209

I suppose my negative experiences with async fall under #3, that it is hard to maintain two APIs. One of the most memorable "real software engineering" bugs of my career involved async Python. I was maintaining a FastAPI server which was consistently leaking file descriptors when making any outgoing HTTP requests due to failing to close the socket. This manifested in a few ways: once the server ran out of available f…

I'm not entirely sure how "3rd party library bug" is python's fault.

Re: Python has had async for 10 years – why isn't it more popular?

#210

The barrier it places in Rust's lib ecosystem is unpleasant; I'm glad it hasn't taken off in Python. I have written too many rust libs because the existing ones forced your code to be Async.

The bifurcation of the Rust ecosystem due to async makes me absolutely loathe the feature, and wish it had never been added to the language. It's so awful.
Post reply on HN