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()
相关推荐
Cha0DD1 小时前
【由浅入深探究langchain】第二十集-SQL Agent+Human-in-the-loop
人工智能·python·ai·langchain
Cha0DD1 小时前
【由浅入深探究langchain】第十九集-官方的SQL Agent示例
人工智能·python·ai·langchain
智算菩萨3 小时前
【Tkinter】4 Tkinter Entry 输入框控件深度解析:数据验证、密码输入与现代表单设计实战
python·ui·tkinter·数据验证·entry·输入框
七夜zippoe3 小时前
可解释AI:构建可信的机器学习系统——反事实解释与概念激活实战
人工智能·python·机器学习·可解释性·概念激活
YuanDaima20486 小时前
[CrewAI] 第15课|构建一个多代理系统来实现自动化简历定制和面试准备
人工智能·python·面试·agent·crewai
WHS-_-20227 小时前
Python 算法题学习笔记一
python·学习·算法
码界筑梦坊7 小时前
353-基于Python的大湾区气候数据可视化分析系统
开发语言·python·信息可视化·数据分析·django·vue·毕业设计
如何原谅奋力过但无声7 小时前
【chap11-动态规划(上 - 基础题目&背包问题)】用Python3刷《代码随想录》
数据结构·python·算法·动态规划
云姜.8 小时前
JSON Schema使用
python·json
Sunshine for you8 小时前
使用Flask快速搭建轻量级Web应用
jvm·数据库·python