airflow中多进程任务中子进程出现ERROR不被抛出的问题

在Python2.7版的airflow(1.10.1版)中,使用multiprocessing时,子进程出现错误,页面上tree view中各个运行节点无错误抛出,如图view log中也没有结果信息打印出来:

使用的multiprocessing中的pool,经查,可以使用pool中的get()函数

    pool = Pool(processes=4)
    rst=[]
    for sql in sql_list:
        # 获取并行处理结果
        rst.append(pool.apply_async(func,(t[0],t[1])))
    pool.close()
    pool.join()
    for r in rst:
        print(r.get())

get()函数在实现 function raise error 时自己也 raise error

class multiprocessing.pool.AsyncResult

The class of the result returned by Pool.apply_async() and Pool.map_async().

get([timeout])

Return the result when it arrives. If timeout is not None and the result does not arrive within timeout seconds then multiprocessing.TimeoutError is raised. If the remote call raised an exception then that exception will be reraised by get().

https://docs.python.org/2/library/multiprocessing.html#multiprocessing.pool.AsyncResult.get

也可以参考:python调用multiprocessing时如何让其抛出错误? - TraderJay's的回答 - 知乎 https://www.zhihu.com/question/54644474/answer/140391537

https://stackoverflow.com/questions/22094852/how-to-catch-exceptions-in-workers-in-multiprocessing

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值