[Twisted-Python] Having some kind of "finally" clause

Vincent Bernat bernat at luffy.cx
Mon Sep 22 07:12:53 MDT 2008


Hi!

I would like to do something like this with Twisted:

x.open()
try:
 x.someoperations()
 x.otheroperations()
finally:
 x.close()

I could do something like this :

d = open_and_get_x()
d.addCallback(someoperations)
d.addCallback(otheroperations)
d.addBoth(closeAndReRaiseIfError)
return d

Each callback would return x to let the next callback proceed it. However,
if there is an error, I have no "x" to close in "closeAndReRaiseIfError".
How can I do that?

Thanks.




More information about the Twisted-Python mailing list