Is this pythonic?

Marko Rauhamaa marko at pacujo.net
Thu Nov 24 05:59:48 EST 2016


Chris Angelico <rosuav at gmail.com>:

> On Thu, Nov 24, 2016 at 7:39 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>>  * Coroutines can be killed, threads cannot.
>
> Not strictly true. A coroutine can be abandoned at an await point, but
> the currently-executed call is still going to complete (usually);

I don't quite understand. Say you are awaiting on receiving bytes from a
socket. That means there has been a nonblocking call to read(2),
recvmsg(2) or equivalent that has returned EAGAIN. If you now abandon
the coroutine, there is no resumption of the system call but the
coroutine can finish instantaneously.

> a thread can be killed, but certain non-interruptible operations will
> delay the termination until after that operation. So either way, the
> operation still runs to completion.

There *could* be such noninterruptible operations (which would be a big
shame). They would have to be implemented with the help of a separate
thread. The surface coroutine can never sit in a blocking operation.


Marko



More information about the Python-list mailing list