jupyter中使用使用事件循环

1、背景

应该在jupyter中遇到过这种问题:

"RuntimeError: This event loop is already running".

这表示,你在jupyter中使用事件循环会出现无法执行,因为他不允许嵌套,所以可以用下面方式解决。

2、方法

By design asyncio does not allow its event loop to be nested. This presents a practical problem: When in an environment where the event loop is already running it's impossible to run tasks and wait for the result. Trying to do so will give the error "RuntimeError: This event loop is already running".

The issue pops up in various environments, such as web servers, GUI applications and in Jupyter notebooks.

This module patches asyncio to allow nested use of asyncio.run and loop.run_until_complete.

复制代码
pip3 install nest_asyncio

import nest_asyncio
nest_asyncio.apply()
相关推荐
狗都不学爬虫_1 分钟前
小程序逆向 - Hai尔(AliV3拖动物品)
javascript·爬虫·python·网络爬虫
abc123456sdggfd11 分钟前
HTML5中Vuex持久化插件中WebStorage的底层配置
jvm·数据库·python
小龙Guo12 分钟前
Yolo 多任务推理,摄像头+视频实时推理,实现关键点、分割、检测等模型推理部署
python·yolo·关键点检测·模型推理
pele13 分钟前
Go语言如何发GET请求_Go语言HTTP GET请求教程【总结】
jvm·数据库·python
weixin_5806140014 分钟前
Go 语言中 go install 命令的正确用法与常见误区详解
jvm·数据库·python
qq_6543669815 分钟前
Bootstrap 5移除jQuery依赖 Bootstrap 5如何不使用jQuery
jvm·数据库·python
m0_6765443817 分钟前
CSS如何实现元素悬浮在页面底部_利用fixed定位与底部间距
jvm·数据库·python
weixin_5689960617 分钟前
Redis怎样监控当前发生了多少次内存驱逐
jvm·数据库·python
2301_7965885018 分钟前
CSS如何制作导航栏平滑移动_使用transition与left属性
jvm·数据库·python
2301_8038756119 分钟前
C#怎么清空Dictionary字典_C#如何管理内存集合【基础】
jvm·数据库·python