繁体   English   中英

为什么多处理挂起?

[英]Why is multiprocessing hanging?

我第一次尝试使用以下代码使用多处理:

def fuzzy_match(blg_matches, op_matches):
    update_dicts = []
    with concurrent.futures.ProcessPoolExecutor() as executor:
        scored_matches = [
            executor.submit(run_matching, blg_match, repeat(op_matches))
            for blg_match in blg_matches
        ]
        for match in concurrent.futures.as_completed(scored_matches):
            update_dicts.append(match)
    return update_dicts

但是,它只是挂起,什么也不做。

为了测试,我将run_matching function 剥离为:

def run_matching(blg_match, op_matches):
    return 2

它仍然挂起。

blg_matchesop_matches都是 SQLAlchemy 查询对象。

关于我哪里出错的任何想法?

所以事实证明这里有两个问题。

  1. 我使用 Windows 并且您需要确保您的多处理代码在if __name__ == "__main__":
  2. 多处理似乎不喜欢 SQLAlchemy 查询对象。 一旦我用列表替换查询,一切正常

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM