平台支撑

这个 asyncio 模块设计为可移植的,但由于平台的底层架构和功能,有些平台有细微的差异和限制。

所有平台

Windows

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


在 3.8 版更改: 在Windows上, ProactorEventLoop 现在是默认事件循环。

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

SelectorEventLoop 有以下限制:

ProactorEventLoop 有以下限制:

Windows系统的单调时钟的分辨率通常在15.6毫秒左右。最佳分辨率为0.5毫秒。分辨率取决于硬件(可用性 HPET )以及Windows配置。

Windows上的子进程支持

在Windows上,默认事件循环 ProactorEventLoop 支持子流程,而 SelectorEventLoop 没有。

这个 policy.set_child_watcher() 函数也不受支持,因为 ProactorEventLoop 有不同的机制来监视子进程。

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)