From 2c271da96508df8460d8bc0e40cd551caca2bebe Mon Sep 17 00:00:00 2001 From: CherryGS <61844819+CherryGS@users.noreply.github.com> Date: Tue, 22 Feb 2022 23:10:18 +0800 Subject: [PATCH] :memo: Add note for `fastapi_reload` option on Windows @CherryGS (#830) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加 `fastapi_reload` 在 win 的额外影响 * :rotating_light: auto fix by pre-commit hooks * Update choose-driver.md * :rotating_light: auto fix by pre-commit hooks * 调整格式 * :rotating_light: auto fix by pre-commit hooks * Update website/versioned_docs/version-2.0.0-beta.2/tutorial/choose-driver.md Co-authored-by: Mix <32300164+mnixry@users.noreply.github.com> * Update website/versioned_docs/version-2.0.0-beta.2/tutorial/choose-driver.md Co-authored-by: Mix <32300164+mnixry@users.noreply.github.com> * Update website/versioned_docs/version-2.0.0-beta.2/tutorial/choose-driver.md Co-authored-by: Mix <32300164+mnixry@users.noreply.github.com> * Update website/versioned_docs/version-2.0.0-beta.2/tutorial/choose-driver.md Co-authored-by: Mix <32300164+mnixry@users.noreply.github.com> * Update website/versioned_docs/version-2.0.0-beta.2/tutorial/choose-driver.md Co-authored-by: Mix <32300164+mnixry@users.noreply.github.com> * Update choose-driver.md * Update choose-driver.md * :memo: update reload warning Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Mix <32300164+mnixry@users.noreply.github.com> Co-authored-by: yanyongyu <42488585+yanyongyu@users.noreply.github.com> --- website/docs/tutorial/choose-driver.md | 23 +++++++++++++++++++ .../tutorial/choose-driver.md | 23 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/website/docs/tutorial/choose-driver.md b/website/docs/tutorial/choose-driver.md index 66f56f4b..955ccfb2 100644 --- a/website/docs/tutorial/choose-driver.md +++ b/website/docs/tutorial/choose-driver.md @@ -99,6 +99,29 @@ app = nonebot.get_asgi() nonebot.run(app="bot:app") ``` +:::warning 警告 +在 Windows 平台上开启该功能有可能会造成预料之外的影响! + +在 `Python>=3.8` 环境下开启该功能后,在 uvicorn 运行时(FastAPI 提供的 ASGI 底层,即 reload 功能的实际来源),asyncio 使用的事件循环会被 uvicorn 从默认的 `ProactorEventLoop` 强制切换到 `SelectorEventLoop` + +> 相关信息参考 [uvicorn#529](https://github.com/encode/uvicorn/issues/529),[uvicorn#1070](https://github.com/encode/uvicorn/pull/1070),[uvicorn#1257](https://github.com/encode/uvicorn/pull/1257) + +后者(`SelectorEventLoop`)在 Windows 平台的可使用性不如前者(`ProactorEventLoop`),包括但不限于 + +1. 不支持创建子进程 +2. 最多只支持 512 个套接字 +3. ... + +> 具体信息参考 [Python 文档](https://docs.python.org/zh-cn/3/library/asyncio-platforms.html#windows) + +所以,一些使用了 asyncio 的库因此可能无法正常工作,如: + +1. [playwright](https://playwright.dev/python/docs/intro#incompatible-with-selectoreventloop-of-asyncio-on-windows) + +如果在开启该功能后,原本**正常运行**的代码报错,且打印的异常堆栈信息和 asyncio 有关(异常一般为 `NotImplementedError`), +你可能就需要考虑相关库对事件循环的支持,以及是否启用该功能 +::: + ##### `fastapi_reload_dirs` 类型:`Optional[List[str]]` diff --git a/website/versioned_docs/version-2.0.0-beta.2/tutorial/choose-driver.md b/website/versioned_docs/version-2.0.0-beta.2/tutorial/choose-driver.md index 66f56f4b..955ccfb2 100644 --- a/website/versioned_docs/version-2.0.0-beta.2/tutorial/choose-driver.md +++ b/website/versioned_docs/version-2.0.0-beta.2/tutorial/choose-driver.md @@ -99,6 +99,29 @@ app = nonebot.get_asgi() nonebot.run(app="bot:app") ``` +:::warning 警告 +在 Windows 平台上开启该功能有可能会造成预料之外的影响! + +在 `Python>=3.8` 环境下开启该功能后,在 uvicorn 运行时(FastAPI 提供的 ASGI 底层,即 reload 功能的实际来源),asyncio 使用的事件循环会被 uvicorn 从默认的 `ProactorEventLoop` 强制切换到 `SelectorEventLoop` + +> 相关信息参考 [uvicorn#529](https://github.com/encode/uvicorn/issues/529),[uvicorn#1070](https://github.com/encode/uvicorn/pull/1070),[uvicorn#1257](https://github.com/encode/uvicorn/pull/1257) + +后者(`SelectorEventLoop`)在 Windows 平台的可使用性不如前者(`ProactorEventLoop`),包括但不限于 + +1. 不支持创建子进程 +2. 最多只支持 512 个套接字 +3. ... + +> 具体信息参考 [Python 文档](https://docs.python.org/zh-cn/3/library/asyncio-platforms.html#windows) + +所以,一些使用了 asyncio 的库因此可能无法正常工作,如: + +1. [playwright](https://playwright.dev/python/docs/intro#incompatible-with-selectoreventloop-of-asyncio-on-windows) + +如果在开启该功能后,原本**正常运行**的代码报错,且打印的异常堆栈信息和 asyncio 有关(异常一般为 `NotImplementedError`), +你可能就需要考虑相关库对事件循环的支持,以及是否启用该功能 +::: + ##### `fastapi_reload_dirs` 类型:`Optional[List[str]]`