[Twisted-Python] Handling errors when using deferToThread

Andrew Bennetts andrew-twisted at puzzling.org
Fri Oct 28 10:56:22 EDT 2005

On Fri, Oct 28, 2005 at 10:35:08AM -0400, Pedro Sanchez wrote:
> This works well as long as doLongCalculation() doesn't fail for
> any reason. But if it does, how can it trigger an errBack?

Just raise an exception.

> I want to do something like this:
> from twisted.internet import threads
> def doLongCalculation():
>     try:
>        # .... do long calculation here ...
>     except:
>        < what can I return here to tell that
>          the calculation failed? >
>     return 3

The literal answer here is a bare raise statement.  But better would be to
not use the try-except at all.

Try inserting something like "1/0" into doLongCalculation and see what


More information about the Twisted-Python mailing list