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():
# 执行一些操作
...
Metadata
Release files for nonebot-plugin-shutdown-hook 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nonebot_plugin_shutdown_hook-0.1.2.tar.gz | 3.2 kB | Without provenance | Details for nonebot_plugin_shutdown_hook-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nonebot_plugin_shutdown_hook-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for nonebot_plugin_shutdown_hook-0.1.2-py3-none-any.whl |
Total release size: 6.8 kB
Release files / nonebot_plugin_shutdown_hook-0.1.2.tar.gz
| Download URL | nonebot_plugin_shutdown_hook-0.1.2.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c52088092c24e7a21a78ad043309f4c94aef5b6cbf77d6e372064e11ff1e605
|
|
BLAKE2b-256 checksum How to use checksums |
5c2b6e48f54f0a2e9717b6956f77028e581134943f53bb2e91158b648bf92d25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.4 Windows/10
|
Release files / nonebot_plugin_shutdown_hook-0.1.2-py3-none-any.whl
| Download URL | nonebot_plugin_shutdown_hook-0.1.2-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e36ce3c8bbbc5c841f9415104f420372385637097d6b1ffe89fd0203d44f46de
|
|
BLAKE2b-256 checksum How to use checksums |
54cd5fbc9968d8d4c8681912d5b05fbb4d49e2f882eee68d4f883f3625a01e50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.4 Windows/10
|
Security for nonebot-plugin-shutdown-hook 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.