diff --git a/nonebot/consts.py b/nonebot/consts.py index c19c5feb..7dc5cff3 100644 --- a/nonebot/consts.py +++ b/nonebot/consts.py @@ -4,6 +4,8 @@ FrontMatter: sidebar_position: 9 description: nonebot.consts 模块 """ +import os +import sys from typing import Literal # used by Matcher @@ -54,3 +56,5 @@ FULLMATCH_KEY: Literal["_fullmatch"] = "_fullmatch" """响应触发完整消息 key""" KEYWORD_KEY: Literal["_keyword"] = "_keyword" """响应触发关键字 key""" + +WINDOWS = sys.platform.startswith("win") or (sys.platform == "cli" and os.name == "nt") diff --git a/nonebot/drivers/none.py b/nonebot/drivers/none.py index dfd2d019..d973399a 100644 --- a/nonebot/drivers/none.py +++ b/nonebot/drivers/none.py @@ -16,6 +16,7 @@ import threading from typing import Set, Union, Callable, Awaitable, cast from nonebot.log import logger +from nonebot.consts import WINDOWS from nonebot.typing import overrides from nonebot.config import Env, Config from nonebot.drivers import Driver as BaseDriver @@ -26,6 +27,8 @@ HANDLED_SIGNALS = ( signal.SIGINT, # Unix signal 2. Sent by Ctrl+C. signal.SIGTERM, # Unix signal 15. Sent by `kill `. ) +if WINDOWS: + HANDLED_SIGNALS += (signal.SIGBREAK,) # Windows signal 21. Sent by Ctrl+Break. class Driver(BaseDriver):