create_connection() is documented as a coroutine. That means you
should be able to catch the error inside another coroutine using a
try/except:
@async.coroutine
def start_it(...):
try:
yield from asyncio.create_connection(...)
except OSError:
<handle error>
You can also convert it to a Future using asyncio.async() and add a
done-callback to check for and handle errors:
def error_handler(f):
try:
f.result()
except OSError:
<handle error>
f = asyncio.async(asyncio.create_connection(...))
f.add_done_callback(error_handler)
Good luck!
On Sat, Jan 4, 2014 at 9:59 AM, Thibaut DIRLIK <[email protected]> wrote:
> Hello !
>
> I'm using a simple asyncio.create_connection() call, put in the event loop
> using asyncio.async.
> If the connection fails, I got an error message (from the logging) module,
> but I can't catch it.
>
> There is no way to define an error callback and I can't use
> run_until_complete() because my
> event loop may already be running (and so it will raise an error). My code
> have to know that
> the connection failed (for example to try connecting again in X secs). How
> can I do ?
>
> Thanks,
>
>
--
--Guido van Rossum (python.org/~guido)