Platform Support

asyncio模块设计为可移植的,但是由于平台的底层体系结构和Function,某些平台存在细微的差异和限制。

All Platforms

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)