From f0c34376fa7485cba216003cd99c3b4ba6b9da9b Mon Sep 17 00:00:00 2001 From: alemidev Date: Mon, 25 Apr 2022 04:43:15 +0200 Subject: [PATCH] keep and expose single loop --- src/treepuncher/traits/runnable.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/treepuncher/traits/runnable.py b/src/treepuncher/traits/runnable.py index eee0d29..7866dce 100644 --- a/src/treepuncher/traits/runnable.py +++ b/src/treepuncher/traits/runnable.py @@ -7,10 +7,12 @@ from signal import signal, SIGINT, SIGTERM, SIGABRT class Runnable: _is_running : bool _stop_task : Optional[asyncio.Task] + _loop : asyncio.AbstractEventLoop def __init__(self): self._is_running = False self._stop_task = None + self._loop = asyncio.get_event_loop() async def start(self): self._is_running = True @@ -32,14 +34,12 @@ class Runnable: signal(SIGINT, signal_handler) - loop = asyncio.get_event_loop() - async def main(): await self.start() while self._is_running: await asyncio.sleep(1) - loop.run_until_complete(main()) + self._loop.run_until_complete(main()) logging.info("Process finished")