[Twisted-Python] Handling errors when using deferToThread
Pedro Sanchez
psanchez at nortel.com
Fri Oct 28 09:25:32 MDT 2005
On Sat, 2005-29-10 at 00:56 +1000, Andrew Bennetts wrote:
> 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.
>
Why? What's the alternative?
> Try inserting something like "1/0" into doLongCalculation and see what
> happens.
>
I don't understand your "1/0" suggestion. Can you elaborate a bit?
Thanks.
--
Pedro
> -Andrew.
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
More information about the Twisted-Python
mailing list