如何停止 Python Websocket 客户端“ws.run_forever" [英] How to stop Python Websocket client "ws.run_forever"

查看:129
本文介绍了如何停止 Python Websocket 客户端“ws.run_forever"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ws.run_forever"启动我的 Python Websocket,另一个 source 表示我应该使用run_until_complete()",但这些函数似乎只适用于 Python asyncio.

I'm starting my Python Websocket using "ws.run_forever", another source stated that I should use "run_until_complete()" but these functions only seem available to Python asyncio.

如何停止 websocket 客户端?或者如何在不永远运行的情况下启动它.

How can I stop a websocket client? Or how to start it withouth running forever.

推荐答案

WebSocketApp 上还有一个 close 方法可以将 keep_running 设置为 False并关闭套接字

There's also a close method on WebSocketApp which sets keep_running to False and also closes the socket

这篇关于如何停止 Python Websocket 客户端“ws.run_forever"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆