[Python-Dev] Importance of "async" keyword

Jim J. Jewett jimjjewett at gmail.com
Sat Jun 27 03:51:07 CEST 2015



On Fri Jun 26 16:51:13 CEST 2015, Paul Sokolovsky wrote:

> So, currently in Python you know if you do:

>    socket.write(buf)

> Then you know it will finish without interruptions for entire buffer.

How do you know that?

Are you assuming that socket.write is a builtin, rather than a
python method?  (Not even a python wrapper around a builtin?)

Even if that were true, it would only mean that the call itself
is processed within a single bytecode ... there is no guarantee
that the write method won't release the GIL or call back into
python (and thereby allow a thread switch) as part of its own
logic.

> And if you write:

>    await socket.write(buf)

> then you know there may be interruption points inside socket.write(),
> in particular something else may mutate it while it's being written.

I would consider that external mutation to be bad form ... at least
as bad as violating the expectation of an atomic socket.write() up
above.

So either way, nothing bad SHOULD happen, but it might anyhow.  I'm
not seeing what the async-coloring actually bought you...

-jJ

--

If there are still threading problems with my replies, please
email me with details, so that I can try to resolve them.  -jJ


More information about the Python-Dev mailing list