平台支持

asyncio 模块旨在实现可移植性,但由于平台底层架构和功能的差异,某些平台存在细微的差异和限制。

所有平台

Windows

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


3.8 版本发生变更: 在 Windows 上,ProactorEventLoop 现在是默认事件循环。

Windows 上的所有事件循环都不支持以下方法

SelectorEventLoop 具有以下限制

ProactorEventLoop 具有以下限制

Windows 上单调时钟的分辨率通常约为 15.6 毫秒。最佳分辨率为 0.5 毫秒。分辨率取决于硬件(HPET 的可用性)和 Windows 配置。

Windows 上的子进程支持

在 Windows 上,默认事件循环 ProactorEventLoop 支持子进程,而 SelectorEventLoop 不支持。

macOS

现代 macOS 版本完全受支持。

macOS <= 10.8

在 macOS 10.6、10.7 和 10.8 上,默认事件循环使用 selectors.KqueueSelector,它不支持这些版本上的字符设备。SelectorEventLoop 可以手动配置为使用 SelectSelectorPollSelector,以支持这些旧版 macOS 上的字符设备。示例

import asyncio
import selectors

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