Files
tg_python/tg_bridge/uvicorn_loop.py
2026-04-23 22:06:19 +08:00

18 lines
589 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Uvicorn 在 Windows 上默认选用 ``ProactorEventLoop``(见 ``uvicorn/loops/asyncio.py``
与 Telethon 经 SOCKS 连接 Telegram DC 时常触发 ``WinError 121``login_cli 使用 Selector 故正常。
本模块提供给 Uvicorn 的 ``loop_factory``,强制使用 ``SelectorEventLoop``。
命令行示例::
uvicorn tg_bridge.app:app --host 0.0.0.0 --port 18080 --loop tg_bridge.uvicorn_loop:selector_loop_factory
"""
from __future__ import annotations
import asyncio
def selector_loop_factory() -> asyncio.AbstractEventLoop:
return asyncio.SelectorEventLoop()