On 2023-01-27 2:14 PM, Frank Millman wrote:

I have changed it to async, which I call with 'asyncio.run'. It now looks like this -

     server = await asyncio.start_server(handle_client, host, port)
     await setup_companies()
     session_check = asyncio.create_task(
         check_sessions())  # start background task

     print('Press Ctrl+C to stop')

     try:
         await server.serve_forever()
     except asyncio.CancelledError:
         pass
     finally:
         session_check.cancel()  # tell session_check to stop running
         await asyncio.wait([session_check])
         server.close()


I don't think I need the 'finally' clause - the cleanup can all happen in the 'except' block.

Frank

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to