Skip to content

Instantly share code, notes, and snippets.

@miku
Created May 13, 2014 18:29
Show Gist options
  • Save miku/8b925b364e6619b4ae07 to your computer and use it in GitHub Desktop.
Save miku/8b925b364e6619b4ae07 to your computer and use it in GitHub Desktop.
from twisted.internet import defer, reactor
def stopping(result):
print('got', result)
# raise RuntimeError('fail')
reactor.stop()
return result
def raiseException(_):
raise Exception()
def handleError():
pass
def printIt(result):
print('----' * 2)
def done(_):
print('done')
d = defer.Deferred()
d.addCallback(done)
reactor.callLater(1, d.callback, True)
# return d
if __name__ == '__main__':
d = defer.Deferred()
# d.addCallback(raiseException)
d.addCallback(printIt)
# d.addErrback(handleError)
d.addBoth(stopping)
reactor.callLater(1, d.callback, True)
print('start')
reactor.run()
print('stop')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment