em___life em___life - 4 months ago 8
Python Question

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)

Answer

You can cancel it...

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

ref

Comments