【问题标题】:Python Multiprocessing TimeOut which sub function and inputsPython Multiprocessing TimeOut 哪个子函数和输入
【发布时间】:2023-01-06 23:39:39
【问题描述】:

我有一个进程,其中有很多子函数使用 Multiprocessing pool.imap_unordered 运行。有时,进程可能会卡住。我目前通过超时管理如下:

futures_res = pool.imap_unordered(ImageRequestedTypeGenerationWrapper, InputData.copy()) 

out1, out2, = futures_res.next(timeout=timeout * 60)

我想确定哪个子函数的参数失败了。 你能建议一个方法吗?

【问题讨论】:

    标签: python timeout python-multiprocessing


    【解决方案1】:

    尝试将对子函数的调用包装在 try-except 块中,并记录发生的任何错误。然后您可以检查日志以查看哪些子函数调用失败。

    def process_subfunction(inputs):
        try:
            # Call subfunction with inputs
            result = subfunction(inputs)
        except Exception as e:
            # Log error and inputs
            logging.error(f"Error occurred while calling subfunction with inputs {inputs}: {e}")
            result = None
        return result
    
    futures_res = pool.imap_unordered(process_subfunction, InputData.copy()) 
    
    out1, out2, = futures_res.next(timeout=timeout * 60)
    

    这将记录调用子函数时发生的任何错误,以及传递给子函数的输入。

    【讨论】:

      猜你喜欢
      • 2021-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-20
      相关资源
      最近更新 更多