On 2/11/2020 2:33 AM, Ben Rudiak-Gould wrote:
On Mon, Feb 10, 2020 at 9:50 AM Andrew Barnert via Python-ideas
<python-ideas@python.org> wrote:
It’s a well-known problem that async is “contagious”: [...]

But C# and every other language that’s borrowed the idea has the same problem, 
and as far as I know, nobody’s thought of a good answer yet.
Threads don't have that problem: you can use non-thread-aware code
with callbacks in your threaded program if you do your own locking.
Haskell (GHC) doesn't have that problem: it has fibers that use a
programming interface like C#/Python threads, but they're multiplexed
by user-mode code within a single OS thread. 16-bit Windows didn't
have that problem. Stackless and greenlet don't have that problem.

It's a problem that can be solved by just doing the obvious thing, the
thing that Python already did with threads: don't define a novel
syntax for coroutines, but instead use the syntax that already
existed.

Async/await syntax is a static type system with two types, may-yield
and will-not-yield. There's no provision for writing
generic/polymorphic code over those types, so you have to write
everything twice. Like any static type system it has some benefits,
but I don't think it's worth the cost, especially in Python, which has
always eschewed mandatory static typing.

I don't know how to fix Python now that it's gone so thoroughly down
this path (starting with the yield keyword 18 years ago). But it's not
a problem that ever needed to exist. Coroutines aren't that hard.

One of the goals of the async/await syntax is to make it clear where control can yield, and therefor where you need to be concerned about mutating state. You don't have this explicitness with threads or with a hypothetical syntax that would hide these yield points,  so you'd need locks. In my experience, incorrect locking is the source of many hard-to-find bugs with threads.

Eric

Eric
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/AUT2VT7R7JF6PPKO6QNQSZSTEXEGER5N/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to