add
This commit is contained in:
parent
6a978c4275
commit
9eff208e8e
@ -434,8 +434,9 @@ def handle_sigint():
|
|||||||
def configure_asyncio_event_loop():
|
def configure_asyncio_event_loop():
|
||||||
"""Configure the appropriate event loop based on the platform"""
|
"""Configure the appropriate event loop based on the platform"""
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
# Windows specific configuration
|
# Windows specific configuration for aiodns compatibility
|
||||||
loop = asyncio.ProactorEventLoop()
|
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||||
|
loop = asyncio.new_event_loop()
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
else:
|
else:
|
||||||
# Unix-like systems configuration
|
# Unix-like systems configuration
|
||||||
@ -464,6 +465,15 @@ def run_server():
|
|||||||
loop.run_until_complete(main())
|
loop.run_until_complete(main())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
handle_sigint()
|
handle_sigint()
|
||||||
|
finally:
|
||||||
|
try:
|
||||||
|
# Clean up pending tasks
|
||||||
|
pending = asyncio.all_tasks(loop)
|
||||||
|
for task in pending:
|
||||||
|
task.cancel()
|
||||||
|
# Give tasks a chance to clean up
|
||||||
|
if pending:
|
||||||
|
loop.run_until_complete(asyncio.gather(*pending, return_exceptions=True))
|
||||||
finally:
|
finally:
|
||||||
loop.close()
|
loop.close()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user