2 ms·
> Are there any downsides to having to explicitly mark an async function using the "async def" syntax? Yes. One main one is splintering the library ecosystem.
by rdtsc 11y ago
> Are there any downsides to having to explicitly mark an async function using the "async def" syntax?
Yes. One main one is splintering the library ecosystem. So some libraries are using Twisted, some are using base threading system, some run in Tornado, some will use async and so on. They are usually not mixable. One day in the distant future they will all support async, but that means updating all of them.
Special markers ("async" waits points/objects) for IO co-routines tend to propagate vertically through all the API layers. If, say, a low level library you found is returning a Deferred/Promise/Future or generates values, then top level has to handle that as well. Then its parent also has to handle it.
It is infecting the ecosystem with low levels details about how the IO needs special casing because of how the GIL works. Yes, it is more elegant in Go, Rust, Erlang, C#, Java etc.
BTW Python has something like it based on the greenlet library (eventlet and gevent libraries are based on). Those monkeypatch system libraries so it manages to hide this complexity, but there are other costs, unsupported or untested side-effects being one.
- mwcampbell 11y agoWhat does the GIL have to do with this? All blocking I/O calls release the GIL.
- rdtsc 11y agoIt's more complicated than that. Specifically having a mix of any CPU and I/O bound threads doesn't play out as nicely: See this: http://dabeaz.blogspot.com/2010/02/revisiting-thread-priorities-and-new.html http://dabeaz.blogspot.com/2010/02/revisiting-thread-priorit... Or even better for a demo watch David Beazley's Pycon 2015 video (It is an awesome video even if you don't care about the GIL or socket programming).