Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Websocket不会永远运行_Python - Fatal编程技术网

Python Websocket不会永远运行

Python Websocket不会永远运行,python,Python,我的pythonwebsocket.py文件在打开10天后会自动关闭,尽管我使用了永远运行 def on_message(ws, message): msg = json.loads(message) #do stuff here def on_error(ws, error): print(error) f = open("websocket_error.txt", "a") #log error f.write(error) time.sle

我的pythonwebsocket.py文件在打开10天后会自动关闭,尽管我使用了永远运行

def on_message(ws, message):
    msg = json.loads(message)
    #do stuff here

def on_error(ws, error):
    print(error)
    f = open("websocket_error.txt", "a") #log error
    f.write(error)
    time.sleep(1)
    run(endpoint) #re-run after 1 sec

def on_close(ws):
    print("### closed. Reconnect will be attempted in 1 second ###")
    ws.close()

def on_open(ws):
    print("### open ###")

def run(endpoint):
    websocket.enableTrace(True)
    ws = websocket.WebSocketApp(endpoint,
                                on_open = on_open,
                                on_message = on_message,
                                on_error = on_error,
                                on_close = on_close)

    ws.run_forever()

if __name__ == "__main__":command = 'subscribe=trade:XBTUSD'
    endpoint = 'wss://www.bitmex.com/realtime?'+command

    run(endpoint)

我试着看看突然关闭是否由错误引起,但日志中没有任何内容。有人有过类似的经历吗?

永远不再是过去的样子:)永远和超越:p。。有严肃的回答吗?你确定bitmex没有断开你的连接吗?你查过什么样的日志?它会失败还是程序崩溃?是否在特定时间每10天一次?如果关闭,您在关闭时收到的事件代码是什么?