Search code examples
pythontwistedautobahntwisted.webtwisted.internet

How to stop Twisted callback?


I wrote a callback function using twisted Now my question is when websocket connection dropped I need to stop this callback.

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) 

Solution

  • You can cancel it...

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

    ref