At Mon, 21 Jun 2010 14:49:02 -0700 (PDT),
Gustaw wrote:
>
> answer - use "catch":
>
> yield catch(client.connect('127.0.0.1', 2775), ClientConnectionError)
>
> Gustaw
Great! Thanks for finding that.
Eric
>
> On 19 Cze, 00:10, Gustaw <[email protected]> wrote:
> > How to handle connection problems in Client?
> > For example if server is not started or I have some network problems.
> >
> > Example:
> >
> > from diesel import Application, Loop, log, Client
> > from diesel.core import ClientConnectionError
> >
> > def req_loop():
> > client = Client()
> > try:
> > yield client.connect('127.0.0.1', 2775)
> > except ClientConnectionError:
> > log.info( "error1" )
> > a.halt()
> >
> > a = Application()
> > log = log.sublog('client', log.info)
> > a.add_loop(Loop(req_loop))
> > a.run()
> >
> > does not work and instead of "error1" I see something like this:
> >
> > === DIESEL ERROR ===
> >
> > Generator stack at time of error:
> >
> > <code object req_loop at 0xb7e5a848, file "http_client.py", line 4>
> > <code object _real_connect at 0xb7c4eba8, file "build/bdist.linux-i686/
> > egg/diesel/client.py", line 84>
> >
> > Standard Traceback:
> >
> > Traceback (most recent call last):
> > File "build/bdist.linux-i686/egg/diesel/core.py", line 244, in
> > cycle_all
> > item = self.current.throw(*error)
> > File "build/bdist.linux-i686/egg/diesel/client.py", line 104, in
> > _real_connect
> > yield cobj
> > ClientConnectionError: [Errno 111] Connection refused
> >
> > Regards,
> > Gustaw