prefer asyncio.get_event_loop instead of asyncio.new_event_loop

This commit is contained in:
hibobmaster 2023-03-07 22:11:16 +08:00
parent fe1a53780d
commit c87a4d3476
Signed by: bobmaster
GPG key ID: 316B77D7914D713C

View file

@ -20,9 +20,9 @@ async def main():
if __name__ == "__main__": if __name__ == "__main__":
try: try:
loop = asyncio.new_event_loop() loop = asyncio.get_event_loop()
asyncio.set_event_loop(loop) task = loop.create_task(main())
asyncio.run(main()) loop.run_until_complete(task)
except KeyboardInterrupt: except KeyboardInterrupt:
loop.close() loop.close()
sys.exit(0) sys.exit(0)