我使用twisted编写了一个回调函数现在我的问题是当websocket连接丢失时我需要停止这个回调。
def sendBack(self, payload):
# find correct way to identify connection dropped now using wasnotcl...
if self.wasNotCleanReason:
# stop this callback
self.sendMessage("Message")
reactor.callLater(delay, self.sendBack, payload=payload)
答案 0 :(得分:0)
你可以cancel
......
callID = reactor.callLater(delay, self.sendBack, payload=payload)
if self.wasNotCleanReason:
callID.cancel()