我已将此示例代码报告为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
,但这似乎是错误的。为什么?