如果joblib并行作业在并行化之前被更新,为什么期望它看到模块变量的过时值?

时间:2019-08-12 08:18:51

标签: python joblib

我已将此示例代码报告为issue,但显然,此代码可以按预期工作:

MyConsts.py

myConst = 1

Bug.py

from joblib import Parallel, delayed

import MyConsts

print(f"we have got myConst == {MyConsts.myConst}")
MyConsts.myConst = 2
print(f"we have set myConst := {MyConsts.myConst}")

def Job(name):
    print(f"{name} sees myConst == {MyConsts.myConst}")

Parallel(n_jobs=1)(delayed(Job)("correct: serial") for _ in range(1))
Parallel(n_jobs=2)(delayed(Job)("a bug? parallel") for _ in range(1))

这将输出:

we have got myConst == 1
we have set myConst := 2
correct: serial sees myConst == 2
a bug? parallel sees myConst == 1

我天真的期望是即使在并行情况下也能看到myConst == 2,但这似乎是错误的。为什么?

0 个答案:

没有答案