python
runtime_error
ai_generated
true
运行时错误:此 Python 版本中 asyncio.run() 不可用
RuntimeError: asyncio.run() is not available in this Python version
ID: python/asyncio-runner-not-available
80%修复率
88%置信度
0证据数
2024-02-28首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.6 | active | — | — | — |
| 3.7 | active | — | — | — |
根因分析
在 Python 3.6 或更早版本中使用 asyncio.run(),该函数在 Python 3.7 中引入。
English
Using asyncio.run() in Python 3.6 or earlier, where it was introduced in Python 3.7.
解决方案
-
85% 成功率 Use asyncio.get_event_loop().run_until_complete() on a new loop
loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) loop.run_until_complete(main())
-
95% 成功率 Upgrade Python to 3.7+
python3 --version # ensure >= 3.7
无效尝试
常见但无效的做法:
-
Using asyncio.get_event_loop().run_until_complete() without checking loop status
60% 失败
If the loop is already running, this may cause 'Event loop is already running' error.
-
Upgrading Python but not updating code
30% 失败
The error is version-specific; upgrading Python resolves it but code may need adjustments.