Issue #22926: In debug mode, call_soon(), call_at() and call_later() methods of

asyncio.BaseEventLoop now use the identifier of the current thread to ensure
that they are called from the thread running the event loop.

Before, the get_event_loop() method was used to check the thread, and no
exception was raised when the thread had no event loop. Now the methods always
raise an exception in debug mode when called from the wrong thread. It should
help to notice misusage of the API.
This commit is contained in:
Victor Stinner 2014-12-26 21:07:52 +01:00
parent d7ff5a5375
commit 956de691f8
6 changed files with 89 additions and 62 deletions

View file

@ -383,7 +383,7 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
sock, protocol, waiter, extra)
def close(self):
if self._running:
if self.is_running():
raise RuntimeError("Cannot close a running event loop")
if self.is_closed():
return
@ -432,9 +432,7 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
self._ssock.setblocking(False)
self._csock.setblocking(False)
self._internal_fds += 1
# don't check the current loop because _make_self_pipe() is called
# from the event loop constructor
self._call_soon(self._loop_self_reading, (), check_loop=False)
self.call_soon(self._loop_self_reading)
def _loop_self_reading(self, f=None):
try: