mirror of
				https://github.com/nonebot/nonebot2.git
				synced 2025-10-31 06:56:39 +00:00 
			
		
		
		
	📝 Add note for fastapi_reload option on Windows @CherryGS (#830)
				
					
				
			* 添加 `fastapi_reload` 在 win 的额外影响 * 🚨 auto fix by pre-commit hooks * Update choose-driver.md * 🚨 auto fix by pre-commit hooks * 调整格式 * 🚨 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 * 📝 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>
This commit is contained in:
		| @@ -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]]`   | ||||
|   | ||||
		Reference in New Issue
	
	Block a user