Python 3检查函数是否在多处理池中执行

时间:2018-06-28 09:59:31

标签: python python-3.x multiprocessing pool

是否可以检查f是否在泳池内?另外,什么是仅捕获特定错误的好捕获?

a = [[1, 2], [1, 2]]

def g(x):
    return x

def f(x):
    try:
        with Pool(2) as p:
            print(p.map(g, x))
    except Exception as e:
        print(type(e))
    return x

with Pool(2) as p:
    print(p.map(f, a))

1 个答案:

答案 0 :(得分:0)

这对我有用

{{1}}