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()
相关推荐
啊阿狸不会拉杆9 分钟前
数据结构-图
java·c语言·数据结构·c++·python·算法·图论
萧鼎24 分钟前
RAGFlow:构建高效检索增强生成流程的技术解析
人工智能·python
cooljser34 分钟前
告别手动操作!用脚本搞定小程序签到的全过程
python
凌叁儿1 小时前
从零开始搭建Django博客①--正式开始前的准备工作
python·django·sqlite
未来之窗软件服务1 小时前
声音分离人声和配乐-从头设计数字生命第5课, demucs——仙盟创梦IDE
ide·macos·xcode·仙盟创梦ide·数字生命
攻城狮7号2 小时前
Python爬虫第19节-动态渲染页面抓取之Splash使用下篇
开发语言·爬虫·python·python爬虫
天天进步20152 小时前
Python项目--基于计算机视觉的手势识别控制系统
开发语言·python·计算机视觉
MarsBighead2 小时前
Pgvector+R2R搭建RAG知识库
python·ai·postgresql·rag·pgvector
綦枫Maple3 小时前
Vue实战(08)解决 Vue 项目中路径别名 `@` 在 IDE 中报错无法识别的问题
前端·ide·vue.js
早睡早起吧3 小时前
目标检测篇---faster R-CNN
人工智能·python·目标检测·计算机视觉·cnn