廖雪峰教程 Day 4 - 编写 Model RuntimeError: Event loop is closed 真让人头大,求大佬相助
程序员文章站
2022-05-13 20:53:09
...
1.测试代码
基于python3.8,python教程地址:https://www.liaoxuefeng.com/wiki/1016959663602400/1018490658464544
test.py:
async def test(loop):
await www.orm.create_pool(loop=loop, host='localhost', port=3306, user='root', password='123456', db='python_test')
u = User(id='129', name='test77')
await u.save()
loop = asyncio.get_event_loop()
loop.run_until_complete(test(loop))
loop.close()
if loop.is_closed():
sys.exit(0)
错误如下
Exception ignored in: <function Connection.__del__ at 0x0000000002E2DC10>
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiomysql\connection.py", line 1072, in __del__
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiomysql\connection.py", line 298, in close
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 108, in close
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 711, in call_soon
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 504, in _check_closed
RuntimeError: Event loop is closed