平臺支持?

asyncio 模塊被設計為可移植的,但由于平臺的底層架構和功能,一些平臺存在細微的差異和限制。

所有平臺?

Windows?

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


在 3.8 版更改: 在 Windows 上,ProactorEventLoop 現在是默認的事件循環(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 上,默認的事件循環(huán) ProactorEventLoop 支持子進(jìn)程,而 SelectorEventLoop 則不支持。

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

macOS?

完整支持流行的macOS版本。

macOS <= 10.8

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

import asyncio
import selectors

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