Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion trio_asyncio/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class TrioEventLoop(BaseTrioEventLoop):
"""

def _queue_handle(self, handle):
self._check_closed()
if self.is_closed():
raise RuntimeError("Event loop is closed")
self._q_send.send_nowait(handle)
return handle

Expand Down
15 changes: 10 additions & 5 deletions trio_asyncio/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ async def run_aio_coroutine(self, coro):

"""
try:
self._check_closed()
if self.is_closed():
raise RuntimeError("Event loop is closed")
fut = asyncio.ensure_future(coro, loop=self)
except BaseException:
coro.close() # avoid unawaited coroutine error
Expand Down Expand Up @@ -393,7 +394,8 @@ def call_soon_threadsafe(self, callback, *args, **context):
Note that the callback is a sync function.
"""
self._check_callback(callback, "call_soon_threadsafe")
self._check_closed()
if self.is_closed():
raise RuntimeError("Event loop is closed")
h = asyncio.Handle(callback, args, self, **context)
self._token.run_sync_soon(self._q_send.send_nowait, h)

Expand Down Expand Up @@ -485,7 +487,8 @@ def run_in_executor(self, executor, func, *args):
Returns an asyncio.Future.
"""
self._check_callback(func, "run_in_executor")
self._check_closed()
if self.is_closed():
raise RuntimeError("Event loop is closed")
if executor is None: # pragma: no branch
executor = self._default_executor
assert isinstance(executor, TrioExecutor)
Expand Down Expand Up @@ -515,7 +518,8 @@ def _handle_sig(self, sig, _):

def add_signal_handler(self, sig, callback, *args):
"""asyncio's method to add a signal handler."""
self._check_closed()
if self.is_closed():
raise RuntimeError("Event loop is closed")
self._check_signal(sig)
if sig == signal.SIGKILL:
raise RuntimeError("SIGKILL cannot be caught")
Expand Down Expand Up @@ -559,7 +563,8 @@ def add_reader(self, fd, callback, *args):

# Local helper to factor out common logic between _add_reader/_add_writer
def _add_io_handler(self, set_handle, wait_ready, fd, callback, args):
self._check_closed()
if self.is_closed():
raise RuntimeError("Event loop is closed")
handle = ScopedHandle(callback, args, self)
old_handle = set_handle(fd, handle)

Expand Down
6 changes: 4 additions & 2 deletions trio_asyncio/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def do_stop():
self._queue_handle(asyncio.Handle(do_stop, (), self))

def _queue_handle(self, handle):
self._check_closed()
if self.is_closed():
raise RuntimeError("Event loop is closed")
if self._glet is not greenlet.getcurrent() and self._token is not None:
self.__run_in_greenlet(_sync, self._q_send.send_nowait, handle)
else:
Expand Down Expand Up @@ -168,7 +169,8 @@ def is_done(_):
return result.unwrap()

def __run_in_greenlet(self, async_fn, *args):
self._check_closed()
if self.is_closed():
raise RuntimeError("Event loop is closed")
if self._loop_running:
raise RuntimeError(
"You can't nest calls to run_until_complete()/run_forever()."
Expand Down
Loading