从asyncio异常手上的future获取参数

2024-09-27 00:21:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个自定义异常处理程序,以便在asynio中的协同例程引发Exception时重新启动连接。在

有一个合作计划,比如:

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

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

^{pr2}$

在应用程序中:

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

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

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


Tags: loopasyncio处理程序getdeviceexceptionnotificationprocess

热门问题