当前位置:网站首页>Asyncio warning deprecationwarning: there is no current event loop
Asyncio warning deprecationwarning: there is no current event loop
2022-07-03 11:24:00 【Little cock Kawaii~】
The following is a code snippet for asynchronous web page fetching :
import asyncio
import aiohttp
async def fetch_page(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
return response.status
tasks = [fetch_page('http://books.toscrape.com') for i in range(50)]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(*tasks))
At present Python Version is 3.10.5, Run the above code , The following warning will appear :
DeprecationWarning: There is no current event loop
loop = asyncio.get_event_loop()
DeprecationWarning: There is no current event loop
loop.run_until_complete(asyncio.gather(*tasks))
All in all asyncio.get_event_loop(), asyncio.gather(*tasks) Neither function can be used .
Code changed to use asyncio.run() , test ok:
import asyncio
import aiohttp
async def fetch_page(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
print(response.status)
async def main():
tasks = [fetch_page('https://quotes.toscrape.com/') for i in range(50)]
await asyncio.gather(*tasks) # argument unpacking: (tasks[0], tasks[1], ... tasks[49])
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(main())
The following statement must be added ,
# important
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
otherwise windows System for https Website , There will be errors
RuntimeError: Event loop is closed
边栏推荐
- ORACLE 11G 单机冷备数据库
- Oracle收回权限 & 创建角色
- Driver development based on I2C protocol
- Summary of interview questions (2) IO model, set, NiO principle, cache penetration, breakdown avalanche
- CSRF
- The element form shows the relationship between elementary transformation and elementary matrix
- .\vmware-vdiskmanager.exe -k “c:\\xxxxx.vmdk”
- 一文搞懂Go语言Context
- 大厂技术专家:工程师如何提升沟通能力?
- Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
猜你喜欢

高精度室内定位技术,在智慧工厂安全管理的应用

MATLAB extrait les données numériques d'un fichier txt irrégulier (simple et pratique)

软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。

FL Studio 20无限试用版水果编曲下载

Lecture 1 number field

EPS电动转向系统分析
![[OBS] configFile in ini format of OBS](/img/b2/0b130cee6ea884557a30e4b408f49e.png)
[OBS] configFile in ini format of OBS

多维度监控:智能监控的数据基础

基于I2C协议的驱动开发

Stack, monotone stack, queue, monotone queue
随机推荐
MATLAB extrait les données numériques d'un fichier txt irrégulier (simple et pratique)
How to become a senior digital IC Design Engineer (1-5) Verilog coding syntax: operand
帝国cms 无缩略图 灵动标签(e:loop)判断有无标题图片(titlepic)的两种写法
在腾讯云容器服务Node上执行 kubectl
Google Earth engine (GEE) - ghsl global population grid dataset 250 meter resolution
Definition and properties of summation symbols
Google Earth Engine(GEE)——GHSL 全球人口网格数据集250米分辨率
"Core values of testing" and "super complete learning guide for 0 basic software testing" summarized by test engineers for 8 years
Summary of interview questions (2) IO model, set, NiO principle, cache penetration, breakdown avalanche
如何成为一名高级数字 IC 设计工程师(1-3)Verilog 编码语法篇:Verilog 行为级、寄存器传输级、门级(抽象级别)
Cuiyusong, CTO of youzan: the core goal of Jarvis is to make products smarter and more reliable
浅析-JMM内存模型
IIS修改配置信息后不生效
表空间创建管理及控制文件管理
软件测试工程师的5年之痒,讲述两年突破瓶颈经验
[vtk] interpretation of source code comments of vtkwindowedsincpolydatafilter
JGG专刊征稿:时空组学
redis那些事儿
大厂技术专家:工程师如何提升沟通能力?
(二)进制