keep and expose single loop

This commit is contained in:
əlemi 2022-04-25 04:43:15 +02:00
parent 4e4bb50e4a
commit f0c34376fa
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E

View file

@ -7,10 +7,12 @@ from signal import signal, SIGINT, SIGTERM, SIGABRT
class Runnable: class Runnable:
_is_running : bool _is_running : bool
_stop_task : Optional[asyncio.Task] _stop_task : Optional[asyncio.Task]
_loop : asyncio.AbstractEventLoop
def __init__(self): def __init__(self):
self._is_running = False self._is_running = False
self._stop_task = None self._stop_task = None
self._loop = asyncio.get_event_loop()
async def start(self): async def start(self):
self._is_running = True self._is_running = True
@ -32,14 +34,12 @@ class Runnable:
signal(SIGINT, signal_handler) signal(SIGINT, signal_handler)
loop = asyncio.get_event_loop()
async def main(): async def main():
await self.start() await self.start()
while self._is_running: while self._is_running:
await asyncio.sleep(1) await asyncio.sleep(1)
loop.run_until_complete(main()) self._loop.run_until_complete(main())
logging.info("Process finished") logging.info("Process finished")