From f4ecb375a6e27a5c431c340070551d9ca8b25bcb Mon Sep 17 00:00:00 2001 From: Brian Guarraci Date: Mon, 1 Jan 2024 15:20:12 -0700 Subject: [PATCH] wait for pending io in kgpy --- scripts/kgpy | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/scripts/kgpy b/scripts/kgpy index 9ab5808..d3ab8e8 100644 --- a/scripts/kgpy +++ b/scripts/kgpy @@ -212,7 +212,6 @@ class ConsoleInputHandler: @staticmethod async def input_producer(console_loop, klong_loop, klong, verbose=False): sys_cmds = create_sys_cmd_functions() - completion_event = threading.Event() try: while True: try: @@ -368,16 +367,15 @@ if __name__ == "__main__": def gather_io_tasks(io_loop): done_event = threading.Event() - # tasks = asyncio.all_tasks(loop=io_loop) - # print(tasks) - # async def main_task(): - # gathered_task = asyncio.gather(*tasks) - # gathered_task.add_done_callback(lambda x: done_event.set()) - # await gathered_task - # if len(tasks) > 1: - # io_loop.call_soon_threadsafe(asyncio.create_task, main_task()) - # else: - # done_event.set() + tasks = asyncio.all_tasks(loop=io_loop) + async def main_task(): + gathered_task = asyncio.gather(*tasks) + gathered_task.add_done_callback(lambda x: done_event.set()) + await gathered_task + if len(tasks) > 1: + io_loop.call_soon_threadsafe(asyncio.create_task, main_task()) + else: + done_event.set() return done_event gather_io_tasks(io_loop).wait()