如何优雅地退出后台守护运行的nonebot v1程序 #157
Answered
by
yanyongyu
CJReinforce
asked this question in
问答
-
如果是前台运行,我知道按下ctrl+c即可,但或许有个问题就是:程序退出前我没有代码去关闭与数据库的连接,或许会造成不好的影响。而大部分情况下,我是用nohup后台守护运行nonebot程序,这个时候我只会kill进程来关闭了,但同样没有办法执行关闭数据库连接。我还想着用代码来实现关闭程序,监听一个命令,接收到命令后就先关闭数据库连接,然后sys.exit()或者raise keyboardinterrupt。我不知道自己的做法是否正确,或者有更优雅的方式? |
Beta Was this translation helpful? Give feedback.
Answered by
yanyongyu
May 29, 2022
Replies: 2 comments 6 replies
-
或许可以使用以下代码,在关闭时处理数据库连接 @get_bot().server_app.after_serving
async def shutdown():
... |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
CJReinforce
-
请问nonebot2中如何进行类似的操作? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
或许可以使用以下代码,在关闭时处理数据库连接