当前位置:网站首页>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
边栏推荐
- [VTK] vtkWindowedSincPolyDataFilter 源码注释解读
- 软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。
- POI excel 单元格换行
- Solution: jupyter notebook does not pop up the default browser
- redis那些事儿
- 帝国cms 无缩略图 灵动标签(e:loop)判断有无标题图片(titlepic)的两种写法
- Analysis of JMM memory model
- [vtk] source code interpretation of vtkpolydatatoimagestencil
- Internet socket (non) blocking write/read n bytes
- 表空间创建管理及控制文件管理
猜你喜欢

Unity移动端游戏性能优化简谱之 画面表现与GPU压力的权衡
![[proteus simulation] 16 channel water lamp composed of 74hc154 four wire to 12 wire decoder](/img/1f/729594930c7c97d3e731987f4c3645.png)
[proteus simulation] 16 channel water lamp composed of 74hc154 four wire to 12 wire decoder

进程与线程

Expandablelistview that can expand and shrink (imitating the list page of professional selection of Zhilian recruitment)

面试题总结(2) IO模型,集合,NIO 原理,缓存穿透,击穿雪崩

软考中级软件设计师该怎么备考

Résumé des questions d'entrevue (2) Modèle io, ensemble, principe NiO, pénétration du cache, avalanche de rupture

用了这么久线程池,你真的知道如何合理配置线程数吗?

The element form shows the relationship between elementary transformation and elementary matrix

My understanding of testing (summarized by senior testers)
随机推荐
POI excel 单元格换行
one hot 独热码
Oracle withdraw permission & create role
Bi skills - permission axis
Analysis of JMM memory model
How to become a senior digital IC Design Engineer (1-3) Verilog coding syntax: Verilog behavior level, register transfer level, gate level (abstract level)
.\vmware-vdiskmanager.exe -k “c:\\xxxxx.vmdk”
Oracle 11g single machine cold standby database
搭建ADG后,实例2无法启动 ORA-29760: instance_number parameter not specified
【obs】obs的ini格式的ConfigFile
MATLAB提取不規則txt文件中的數值數據(簡單且實用)
AIDL
Function details of CorelDRAW graphics suite 2022
英特尔13代酷睿旗舰曝光,单核5.5GHz
Matlab extracts numerical data from irregular txt files (simple and practical)
Error installing the specified version of pilot
【obs】封装obs实现采集的基础流程
Processes and threads
[OBS] configFile in ini format of OBS
如何让让别人畏惧你