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

Martin Teichmann lkb.teichmann at gmail.com
Fri Oct 7 04:07:36 EDT 2016


Hi list,

I am currently developing a Python library based on asyncio.
Unfortunately, not all users of my library have much experience with
asynchronous programming, so they often try to use blocking functions.

I thought it would be a good idea if we could somehow flag blocking
functions in the standard library, such that they issue a warning (or
even raise an exception) if they are used in an asyncio context. For
functions implemented in Python, a simple decorator should do the job.

For functions implemented in C, things get a bit more complex.
Thinking about it, I realized that currently the best indicator for a
C function to block is that it releases the GIL. There are some false
positives, like a read with O_NONBLOCK set, in which case we need a
way to opt out, but in general it could be a good idea that releasing
the GIL triggers a warning in an asyncio environment.

Greetings

Martin


More information about the Python-ideas mailing list