Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lfdversluis/855038617d767dc4b72086dae8f9b462 to your computer and use it in GitHub Desktop.
Save lfdversluis/855038617d767dc4b72086dae8f9b462 to your computer and use it in GitHub Desktop.
python twisted failure check problem
from twisted.internet.error import ConnectingCancelledError
from twisted.internet.defer import Deferred, CancelledError
# This prints no - it doesn't work
d = Deferred()
def on_error(failure):
if failure.check([ConnectingCancelledError, CancelledError]):
print "ok"
else:
print "no"
print failure
d.addErrback(on_error)
d.cancel()
## This one does work - it prints ok
d = Deferred()
def on_error(failure):
if failure.check(CancelledError):
print "ok"
else:
print "no"
print failure
d.addErrback(on_error)
d.cancel()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment