高优先级关闭信号钩子插件
Project description
nonebot-plugin-shutdown-hook
该插件提供一个高优先级关闭信号钩子,用于在关闭时,Bot断开之前执行一些操作 例如对所有未关闭的Matcher进行回复,修改Bot昵称或签名为已关机等
在 nonebot.run() 之前调用此函数, 用 on_shutdown_before 装饰需要执行的函数即可
通过修改 Server.handle_exit,在 handle_exit 函数接收到中止信号后并不立刻中止,而是将信号存储在 SIGNALS_LIST,并立刻执行注册的钩子函数。钩子函数执行完毕后,依次从 SIGNALS_LIST 取出信号,重新传入原 handle_exit 函数处理。
此钩子优先级非常高,如果在钩子时发生错误,可能会导致程序无法正常关闭。
安装
pip install nonebot-plugin-shutdown-hook
使用
导入
from nonebot-plugin-shutdown-hook import override_uvicorn_shutdown_hooks, on_shutdown_before
创建
# bot.py 文件
...
override_uvicorn_shutdown_hooks()
...
if __name__ == "__main__":
nonebot.run()
...
@on_shutdown_before()
async def func():
# 执行一些操作
...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for nonebot_plugin_shutdown_hook-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41219de308709cdecaff639f95aad649ead186778eb396149d073a647a3b2656 |
|
MD5 | 18a5d62200f32e98e5636ca52424bdcc |
|
BLAKE2b-256 | 707a89c612074c34ba3cceceb600512a299b3667bad11c67bc505534978f16b0 |
Close
Hashes for nonebot_plugin_shutdown_hook-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 354da6f13f446c55d1e1c28735b9eeb3f5efdb7e61a6c34314625db62ff003a4 |
|
MD5 | abbeaf4b9bec7579008bc8a5079abe41 |
|
BLAKE2b-256 | 620704987ad4886dfb28039d90095bfc9c78542fdb60d78461a56a916fce90e0 |