Skip to content

Commit

Permalink
wait for pending io in kgpy
Browse files Browse the repository at this point in the history
  • Loading branch information
briangu committed Jan 1, 2024
1 parent ed2ec0c commit f4ecb37
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions scripts/kgpy
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit f4ecb37

Please sign in to comment.