平臺(tái)支持?

asyncio 模塊被設(shè)計(jì)為可移植的,但由于平臺(tái)的底層架構(gòu)和功能,一些平臺(tái)存在細(xì)微的差異和限制。

所有平臺(tái)?

Windows?

源代碼: Lib/asyncio/proactor_events.py, Lib/asyncio/windows_events.py, Lib/asyncio/windows_utils.py


在 3.8 版更改: 在 Windows 上,ProactorEventLoop 現(xiàn)在是默認(rèn)的事件循環(huán)。

Windows上的所有事件循環(huán)都不支持以下方法:

SelectorEventLoop 有下列限制:

ProactorEventLoop 有下列限制:

The resolution of the monotonic clock on Windows is usually around 15.6 milliseconds. The best resolution is 0.5 milliseconds. The resolution depends on the hardware (availability of HPET) and on the Windows configuration.

Windows的子進(jìn)程支持?

在 Windows 上,默認(rèn)的事件循環(huán) ProactorEventLoop 支持子進(jìn)程,而 SelectorEventLoop 則不支持。

也不支持 policy.set_child_watcher() 函數(shù),ProactorEventLoop 有不同的機(jī)制來(lái)監(jiān)視子進(jìn)程。

macOS?

完整支持流行的macOS版本。

macOS <= 10.8

在 macOS 10.6, 10.7 和 10.8 上,默認(rèn)的事件循環(huán)使用 selectors.KqueueSelector,在這些版本上它并不支持字符設(shè)備。 可以手工配置 SelectorEventLoop 來(lái)使用 SelectSelectorPollSelector 以在這些較老版本的 macOS 上支持字符設(shè)備。 例如:

import asyncio
import selectors

selector = selectors.SelectSelector()
loop = asyncio.SelectorEventLoop(selector)
asyncio.set_event_loop(loop)