Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 程序无法退出 #1039

Closed
3 tasks done
jiaigo opened this issue Jul 10, 2023 · 9 comments
Closed
3 tasks done

[BUG] 程序无法退出 #1039

jiaigo opened this issue Jul 10, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@jiaigo
Copy link

jiaigo commented Jul 10, 2023

提交 issue 前,请先确认:

  • 我已看过 FAQ,此问题不在列表中
  • 我已看过其他 issue,他们不能解决我的问题
  • 我认为这不是 Mirai 或者 OpenAI 的 BUG

表现

  1. 无法 Ctrl+C 退出,请问是什么原因,是否与creart创建的loop有关
  2. 图2的loop.run_forever() 注释后也是一样无法 Ctrl+C 退出

截图
微信截图_20230710112055
微信截图_20230710112215

@jiaigo jiaigo added the bug Something isn't working label Jul 10, 2023
@Haibersut
Copy link
Collaborator

http模式下的已知问题

@Haibersut
Copy link
Collaborator

目前缓解措施如下:
将bot.py中的hook()调整到loop.run_until_complete(asyncio.gather(*bots))
image

然后在utils文件夹的exithooks.py中,开头导入
import os
from constants import config
image

然后修改exit_gracefully函数
image

在出现
2023-07-10 21:11:21.875 | INFO | main::54 - [Edge TTS] 读取成功!
后即可随时关闭。

@Haibersut
Copy link
Collaborator

看错了,hook加在try前面好一些
image

@jiaigo
Copy link
Author

jiaigo commented Jul 10, 2023

按照上述代码进行修改,仍旧无法解决问题,且没有输出上述定义的log信息,即logger.warning
image

@Haibersut
Copy link
Collaborator

我试了下还是hook位置的问题,还是要将bot.py中的hook()调整到loop.run_until_complete(asyncio.gather(*bots))前
image

@jiaigo
Copy link
Author

jiaigo commented Jul 11, 2023

有两点疑问:

  1. 从调整的顺序来看,如何理解hook与loop.create_task,loop.run_until_complete之间的关系,个人测试creat_task -> run_until_complete -> hook -> run_until_complete是可以进入exit_grace函数的,但期待一个合理的解释
  2. 关于sys.exit和os._exit,后者无释放资源 (如线程锁),强制退出,前者会陷入lock释放的死循环,不知可否考虑优化前者,而不是暴力退出😀

以上是些许疑问,当前issue已解决

@jiaigo jiaigo closed this as completed Jul 11, 2023
@Haibersut
Copy link
Collaborator

理论上来说,hook函数在 bot.py 中的位置决定了何时开始捕获sigint信号,但是尝试下来放在全部启动完成后可以正常关闭http服务,所以也就是个经验,所以很迷惑的就是不知道为什么放在最开始不行

由于http服务不是我写的,我要看一下才能知道,可能是监听或者开了别的线程的问题

暴力退出剩下的交给操作系统(bushi

@Haibersut
Copy link
Collaborator

看起来是因为多开了几个别的线程导致信号无法给到全部线程

开启HTTP后
0 KX}DUE{)07`I%30C@G{ U

未开启HTTP
)8 3_NE3H`_FSZ06N6{9~B6

@jiaigo
Copy link
Author

jiaigo commented Jul 11, 2023

理论上来说,hook函数在 bot.py 中的位置决定了何时开始捕获sigint信号,但是尝试下来放在全部启动完成后可以正常关闭http服务,所以也就是个经验,所以很迷惑的就是不知道为什么放在最开始不行

由于http服务不是我写的,我要看一下才能知道,可能是监听或者开了别的线程的问题

暴力退出剩下的交给操作系统(bushi

你可以试试将edeg_tts那段注释,一样无法exit,就算是放在启动http服务前面那行

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants