Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from twisted.internet import task
- from twisted.internet import reactor
- datagramRecieved = False
- timeout = 1.0 # One second
- # UDP code here
- def testTimeout():
- global datagramRecieved
- if not datagramRecieved:
- reactor.stop()
- datagramRecieved = False
- l = task.LoopingCall(testTimeout)
- l.start(timeout) # call every second
- # l.stop() will stop the looping calls
- reactor.run()
- class Protocol(DatagramProtocol):
- def __init__(self, timeout):
- self.timeout = timeout
- def datagramReceived(self, datagram):
- self.timeout.cancel()
- # ...
- def datagramReceived(self, datagram):
- self.timeout.cancel()
- # ...
Add Comment
Please, Sign In to add comment