国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

linux - Python中aysncio的事件循環(huán)是屬于線程還是進(jìn)程?

瀏覽:124日期:2022-09-09 13:37:54

問題描述

默認(rèn)的get_event_loop獲取的loop是基于線程還是進(jìn)程,找了很久的官方文檔才找到這么一句描述,看起來是屬于當(dāng)前線程的?

18.5.2.4. Event loop policies and the default policyFor most users of asyncio, policies never have to be dealt with explicitly, since the default global policy is sufficient. The default policy defines context as the current thread, and manages an event loop per thread that interacts with asyncio. The module-level functions get_event_loop() and set_event_loop() provide convenient access to event loops managed by the default policy.

那么官方文檔提供的另外兩個(gè)獲取事件循環(huán)(下面的pre塊)方法一般用于什么地方?關(guān)于事件循環(huán)嘗試看了源碼但涉及到多路IO復(fù)用問題遂放棄,求各位網(wǎng)友的指點(diǎn)?

loop = asyncio.new_event_loop()asyncio.set_event_loop(loop)

問題解答

回答1:

屬于協(xié)程,即用戶態(tài)線程,在單條內(nèi)核線程上分出多個(gè)用戶線程,本質(zhì)還是單線程,算是一個(gè)高級(jí)語法糖,讓你可以用同步的寫法實(shí)現(xiàn)異步的效果(io多路復(fù)用維護(hù)起狀態(tài)來是相當(dāng)惡心的,現(xiàn)在交由asyncio來幫你維護(hù)了)

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 庄河市| 江北区| 西畴县| 荣成市| 大邑县| 新建县| 宣威市| 涿鹿县| 丹棱县| 民乐县| 营山县| 保靖县| 洞头县| 汕尾市| 乌拉特中旗| 铅山县| 景宁| 长岛县| 耒阳市| 紫云| 华阴市| 荆州市| 兴义市| 开平市| 常熟市| 海门市| 闽清县| 海原县| 西乡县| 庆元县| 牡丹江市| 安庆市| 阳城县| 深泽县| 泰和县| 沐川县| 湛江市| 藁城市| 锡林郭勒盟| 广昌县| 环江|