From d0a2a59de0fe50b4be97b77169ee943f410bc1bc Mon Sep 17 00:00:00 2001 From: hassanselim0 Date: Tue, 9 Apr 2024 21:58:18 +0200 Subject: [PATCH] fix: service class trying to get event loop on init (#61) The `_new_*_event` methods on the `Service` class were calling the `loop` property instead of using the `_loop` attribute, the property tried to fetch the current thread's event loop which caused some odd issues, this fix delays that until the event loop is actually needed (lazy loading). --- mode/services.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mode/services.py b/mode/services.py index e8850f1..228e118 100644 --- a/mode/services.py +++ b/mode/services.py @@ -596,16 +596,16 @@ def __init__( super().__init__(loop=self._loop) def _new_started_event(self) -> Event: - return Event(loop=self.loop) + return Event(loop=self._loop) def _new_stopped_event(self) -> Event: - return Event(loop=self.loop) + return Event(loop=self._loop) def _new_shutdown_event(self) -> Event: - return Event(loop=self.loop) + return Event(loop=self._loop) def _new_crashed_event(self) -> Event: - return Event(loop=self.loop) + return Event(loop=self._loop) async def transition_with( self, flag: str, fut: Awaitable, *args: Any, **kwargs: Any