[Python-ideas] Flagging blocking functions not to be used with asyncio

Martin Teichmann lkb.teichmann at gmail.com
Mon Oct 10 05:59:11 EDT 2016


Hi,

> Honestly before writing a lot of code here I'd like to hear more from
> Martin about the spread of mistakes he's observed among his users.

Over the weekend, I tried to classify the mistakes I found. Most of
the times, it's something like "I'm just doing a quick lookup on the
database, that shouldn't be a problem". For people coming from a
threading background, this are indeed fast operations, they don't
consider such calls as blocking. In the end, it all boils down to some
read operation down in some non-asyncio code.

This is why I got my idea to flag such calls. Unfortunately, I
realized that it is nearly impossible to tell whether a read call is
blocking or not. We would need to know whether the file descriptor we
read from was created as non-blocking, or whether it was an actual
file, and how fast the file storage is for this file (SSD: maybe fine,
Network: to slow, magnetic disk: dunno). All of this is unfortunately
not a Python issue, but an issue for the underlying operating system.

So I guess I have to tell my users to program carefully and think
about what they're reading from. No automatic detection of problems
seems to be possible, at least not easily.

Greetings

Martin


More information about the Python-ideas mailing list