[Twisted-Python] Handling errors when using deferToThread
cwmoad at gmail.com
Fri Oct 28 11:39:30 EDT 2005
This will raise a dividebyzero error. In which case your errback will
be called. You don't need the try/except block because when an
exception is raised your errback will be called instead of the
On 10/28/05, Pedro Sanchez <psanchez at nortel.com> wrote:
> 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?
> > -Andrew.
> > _______________________________________________
> > Twisted-Python mailing list
> > Twisted-Python at twistedmatrix.com
> > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
More information about the Twisted-Python