get arguments from future on asyncio exception handler

Viewed 423

I am trying to create a custom exception handler to restart a connection when a Exception is raised by a coroutine in asynio.

Having a coroutine like:

@asyncio.coroutine
def process_notification(device):
    results = yield from get_notifications(device)
    # here I am creating other tasks
    return result

The custom exception handler is defined as follows:

def custom_exception_handler(loop, context):
    asyncio.base_events.BaseEventLoop.default_exception_handler(loop, context)

    future = context.get('future')
    #TODO: how to get the argument device and create a new task with it

And in the application:

...
loop = asyncio.get_event_loop()
loop.set_exception_handler(custom_exception_handler)

task = asyncio.ensure_future(process_notification(device))
...

As seen, in the TODO, I am missing how to get the arguments from the task initial call.

0 Answers
Related