PaddleOCR icon indicating copy to clipboard operation
PaddleOCR copied to clipboard

修复多进程下ModuleNotFoundError: No module named 'paddleocr.ppstructure'的问题

Open hermitgreen opened this issue 2 years ago • 1 comments

原有实现中,同名Module(paddleocr)下使用同名的Python主入口脚本(paddleocr.py),使用spawn多进程,在Python3.8触发ModuleNotFoundError的bug,该bug在测试环境(Python3.8.15 Paddle2.2.2 PaddleOCR2.6.0.1)可以稳定复现

CASE代码:

from paddleocr.ppstructure.predict_system import StructureSystem
import multiprocessing

def func(
    pid,
):
    print(f"[{pid}] Start")
    [_ for _ in range(int(1e6))]
    print(f"[{pid}] Finished")


if __name__ == '__main__':
    with multiprocessing.Manager() as manager:
        procs = []
        for i in range(2):
            p = multiprocessing.get_context("spawn").Process(
                target=func,
                args=(f"pid_{i}",)
            )
            p.start()
            procs.append(p)

        for p in procs:
            p.join()

修复前: image

修复后: image

hermitgreen avatar Oct 20 '22 03:10 hermitgreen

Thanks for your contribution!

paddle-bot[bot] avatar Oct 20 '22 03:10 paddle-bot[bot]