在 asyncio 异常处理程序上从未来获取参数

ait*_*rhh 5 python python-asyncio

我正在尝试创建一个自定义异常处理程序,以便Exceptionasynio.

有一个协程,如:

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

自定义异常处理程序定义如下:

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
Run Code Online (Sandbox Code Playgroud)

在应用程序中:

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

task = asyncio.ensure_future(process_notification(device))
...
Run Code Online (Sandbox Code Playgroud)

正如所见,在 TODO 中,我缺少如何从任务初始调用中获取参数。