[issue33605] Detect accessing event loop from a different thread outside of _debug

Andrew Svetlov report at bugs.python.org
Wed May 23 16:08:36 EDT 2018


Andrew Svetlov <andrew.svetlov at gmail.com> added the comment:

Heh, should we sacrifice performance?
Documentation for asyncio explicitly states that the only safe interthreading call is `call_soon_threadsafe()`.

If people use multithreaded environments with asyncio (Why? Usually `run_in_executor()` doesn't require communication with loop. Maybe they trying to do strange things like fetching web pages using aiohttp from Django application?) -- they should be aware of problems and consequences.

Like threaded programming is potentially dangerous without locks and other things.

I very doubt that correct asyncio program have problems like this. In opposite `call_soon()` is maybe the hottest path of asyncio, it should be as fast as possible. Any slowdown is not desirable.

P.S. I believe teaching people to get rid of `run_until_complete()` but switching to `asyncio.run()` can help better than anything else.

P.P.S. If a user wants to shoot in own leg -- nobody can stop it. Don't underestimate people's inventiveness.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33605>
_______________________________________


More information about the Python-bugs-list mailing list