如何阻止Twisted回调?

时间:2016-07-20 14:35:09

标签: python twisted autobahn twisted.web twisted.internet

我使用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) 

1 个答案:

答案 0 :(得分:0)

你可以cancel ......

callID = reactor.callLater(delay, self.sendBack, payload=payload)
    if self.wasNotCleanReason:
        callID.cancel()

ref