Skip to content

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

@RockChinQ

Description

@RockChinQ

我在为我的项目实现一个热重载功能,需要关闭 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 仅为局部变量,没有被暴露给上层调用者,如何操作?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions