runtimeerror no running event loop discord py You might have gotten the runtime error, no running event loop error while working on Discord bots. With asyncio, you can not curate nested loops. This is due to the
asyncio.get_running_loop() # 报错信息如下 # RuntimeError: no running event loop (2) loop=asyncio.get_event_loop() 获得一个事件循环,如果当前线程没有事件循环则创建一个新的事件循环,等同于asyncio.new_event_loop() 举例经常用到,暂无示例 (3)loop=asyncio.set_event_loop(loop) 不清楚怎么使用,没...
loop.run_until_complete(hello()) # 在这个位置运行获取在运行的事件循环会报错,因为事件循环处于未运行状态 asyncio.get_running_loop() # 报错信息如下 # RuntimeError: no running event loop 1. 2. 3. 4. 5. 6. 7. 8. (2) loop=asyncio.get_event_loop() 获得一个事件循环,如果当前线程没有事...
()) File "/Users/kbrazil/.pyenv/versions/3.11.1/lib/python3.11/site-packages/prompt_toolkit/application/application.py", line 1057, in create_background_task loop = self.loop or get_running_loop() ^^^ RuntimeError: no running event loop sys:1: RuntimeWarning: coroutine 'Buffer._create...
Consider also using the asyncio.run() function instead of using lower level functions to manually create and close an event loop.Deprecated since version 3.10: Deprecation warning is emitted if there is no running event loop. In future Python releases, this function will be an alias of get_...
print(loop) # 创建事件循环对象 loop = asyncio.get_event_loop() asyncio.get_running_loop() 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 报错信息如下 RuntimeError: no running event loop 1. 为什么会报错,因为事件循环对象没有运行或者是运行结束,当代码执行到asyncio.get_running_loop()这一步...
import asyncio try: loop = asyncio.get_running_loop() except RuntimeError: print("No loop running") 在Python 3.7 中,有两种有效的方法来获取当前正在运行的循环实例。 我们可以调用 asyncio.get_event_loop 或 asyncio.get_running_loop 但asyncio.get_event_loop 内部是做了什么?大概下面几点 1.检查在...
他会报错 Event loop is running. 如果写成: self.loop = asyncio.get_event_loop() res = self.loop.run_until_complete(self.resolver.query(host=host, qtype='A')) 他会报错 loop argument must agree with Future 得 asyncio.ensure_future(self.resolver.query(host=host, qtype='A'), loop=self...
importnest_asyncionest_asyncio.apply() 查阅资料后发现,发现使用jupyter notebook环境,其连接着 IPython 内核,而 IPython 内核本身在事件循环上运行,而 asyncio 不允许嵌套其事件循环,因此会出现如上图的错误信息。 nest_asyncio 作为异步操作的补丁而存在,具体内容请参考:...
他会报错 Event loop is running. 如果写成: self.loop = asyncio.get_event_loop() res = self.loop.run_until_complete(self.resolver.query(host=host, qtype='A')) 他会报错 loop argument must agree with Future 得 asyncio.ensure_future(self.resolver.query(host=host, qtype='A'), loop=self...