[Twisted-Python] Catching error in protocol.ReconnectingClientFactory

gelin yan dynamicgl at gmail.com
Mon Jun 25 16:47:35 MDT 2012


On Tue, Jun 26, 2012 at 5:47 AM, Martin <martin at webscio.net> wrote:

> On 25/06/12 22:27, Adrian Overbury wrote:
> > On 25/06/2012, at 10:16 PM, Martin <martin at webscio.net> wrote:
> >
> >> On 14/06/12 12:38, Martin wrote:
> >>> Hi, thanks for your reply.
> >>>
> >>> Indeed, the ReconnectingClientFactory is being sent the Failure object
> to
> >>>
> >>> def clientConnectionLost(self, connector, reason):
> >>>         log.msg('Lost connection. Reason: %s' % reason)
> >>> protocol.ReconnectingClientFactory.clientConnectionLost(self,
> >>> connector, reason)
> >>>
> >>> where "reason" is the Failure object that is "unhandled". is there
> >>> anything I could do to it there to make it handled?
> >>>
> >>> Also, the documentation in
> >>> http://twistedmatrix.com/documents/current/core/howto/defer.html says
> >>> that one can do d.addErrback(err.log) to deal with unhandled errors,
> >>> but what is d?
> >>>
> >>> In general, I'm not doing anything special.. I'm creating a
> >>> ReconnectingClientFactory and connecting it to a server..
> >>> f = MyReconnectingClientFactory(..)
> >>> reactor.connectSSL(url, port, f, ssl.ClientContextFactory())
> >>> reactor.run()
> >>>
> >>> Basically it. Any thoughts? Thanks a lot!
> >>>> On Jun 11, 2012, at 8:01 AM, Martin wrote:
> >>>>
> >>>>> Hi there,
> >>>>>
> >>>>> I've been looking around for a solution for several hours now, and
> >>>>> maybe
> >>>>> I'm just missing something..
> >>>>>
> >>>>> I've a factory that implements protocol.ReconnectingClientFactory
> which
> >>>>> works just fine, however, whenever the program ends running, I get a
> >>>>> bunch of Unhandled error in Deferred messages in my log for each
> >>>>> disconnection that occurred during runtime, such as Failure:
> >>>>> twisted.internet.error.ConnectionLost: ...
> >>>>>
> >>>>> Is there any way I could somehow "handle" these during runtime, so
> that
> >>>>> my log wouldn't be spammed with this at the end.. (or avoid it being
> >>>>> spammed somehow..)
> >>>> These messages are coming from some code which is issuing Deferreds,
> >>>> not from ReconnectingClientFactory.  You need to add an errback to
> >>>> those Deferreds in your application code.  There's no way to write a
> >>>> catch-all, just like there's no way to write a catch-all that can
> >>>> stop exceptions from being raised in basic Python.
> >>>>
> >>>> I can't say more without a code example, preferably
> >>>> a<http://sscce.org/>.
> >>>>
> >>>> -glyph
> >>>>
> >>>>
> >>>> _______________________________________________
> >>>> Twisted-Python mailing list
> >>>> Twisted-Python at twistedmatrix.com
> >>>> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> >>>>
> >>>>
> >> No suggestions as to how I could get rid of this? :(
> >>
> >>
> > I believe glyph gave you the answer to that already.  In your example
> above of d.addErrBack, d is the deferred object.  Each of those needs to
> have an errback handler attached to it.  If you don't want to see anything
> out of them, simply don't print anything.
> >
> >> _______________________________________________
> >> 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
> > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> >
> >
> Well, kind of - I know that I need to do addErrBack on the deferred
> objects, I kind of knew that when I asked the original question having
> read the documentation on deferreds. What I still don't know though is
> how am I supposed to catch these deferreds - that is not being explained
> anywhere in the documentation I'm afraid.
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>

Hi
   Usually you don't need to catch a deferred object..adding some callbacks
is enough..

I admit it might not be intuitive to understand defer concept at your first
trial. But it is powerful & elegant.

Regards

gelin yan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20120626/93c5f2ba/attachment.html>


More information about the Twisted-Python mailing list