Closed c0deaddict closed 6 years ago
Found out that relinquishing cpu before closing allows time for the background tasks to complete. Have a working fix now in this PR: https://github.com/nats-io/asyncio-nats/pull/69
async def signal_handler():
if nc.is_closed:
return
print('Disconnecting from NATS...')
await nc.close()
await asyncio.sleep(0) # <--- allow tasks to complete in the background
pending = asyncio.Task.all_tasks()
for task in pending:
print('Task is still running: {} cancelled? {}'.format(task, task.cancelled()))
After closing the connection with close() some tasks keep running for a few seconds. I expected that 'await nc.close()' would wait until all tasks are cancelled and stopped.
Sample code:
This is the output I get, you can see some tasks are still running.