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

请问如何在运行期间动态关闭/重启连接? #222

Open
RockChinQ opened this issue Nov 15, 2024 · 0 comments
Open

请问如何在运行期间动态关闭/重启连接? #222

RockChinQ opened this issue Nov 15, 2024 · 0 comments

Comments

@RockChinQ
Copy link

我在为我的项目实现一个热重载功能,需要关闭 qq-botpy 的实例,再重新创建

现在我在 关闭实例的代码中调用了 bot.close()

    async def kill(self) -> bool:
        if not self.bot.is_closed():
            await self.bot.close()
            return True

同时,我的程序已经对运行 bot.start() 的协程做了 cancel操作:

图1:我的程序如何启动 botpy 实例
image

图2:我的程序如何关闭实例
image
image
image

但执行完成后,仍然会继续处理ws收到的消息。

image

我在 botpy/gateway.py 中找到了这些代码,这里的循环检查 ws_conn 的 closed 状态,并在closed时退出,但ws_conn 仅为局部变量,没有被暴露给上层调用者,如何操作?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant