From 8e8d5cd36aae1a5b1d1a94ae258cdcb760e72ebc Mon Sep 17 00:00:00 2001 From: Michael Pilosov Date: Sun, 19 Mar 2023 19:33:52 -0600 Subject: [PATCH] support python 3.6+ by changing to ensure_future. --- src/announce_server/server.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/announce_server/server.py b/src/announce_server/server.py index 8d6ba35..da0ddbe 100644 --- a/src/announce_server/server.py +++ b/src/announce_server/server.py @@ -137,10 +137,18 @@ def start_server(address, port, heartbeat_interval, heartbeat_timeout): The timeout for waiting for a response in seconds. """ loop = asyncio.get_event_loop() - heartbeat_task = loop.create_task( + # Python 3.7+, coroutines only: + # heartbeat_task = loop.create_task( + # heartbeat(sio, heartbeat_interval, heartbeat_timeout) + # ) + # aiohttp_app = loop.create_task(web._run_app(app, host=address, port=port)) + + # Python 3.6+ compatible. Supports any awaitable: + heartbeat_task = asyncio.ensure_future( heartbeat(sio, heartbeat_interval, heartbeat_timeout) ) - aiohttp_app = loop.create_task(web._run_app(app, host=address, port=port)) + + aiohttp_app = asyncio.ensure_future(web._run_app(app, host=address, port=port)) exit_handler = create_exit_handler(loop, heartbeat_task) signal.signal(signal.SIGINT, exit_handler)