@
Sylv 代码比较不堪入目,不太好意思上
现在已经锁定问题了:
=========================
#coding:utf-8
import multiprocessing
globalVar = '?'
def func1():
global globalVar
globalVar = '!'
print 'in func1, globalVar =', globalVar
def func2(arr):
global globalVar
print 'in func2, globalVar =', globalVar
def main():
global globalVar
func1()
print 'in main, globalVar =', globalVar
pool = multiprocessing.Pool(processes = 1)
pool.map(func2, [0])
pool.close()
pool.join()
if __name__ == '__main__':
main()
输出:
in func1, globalVar = !
in main, globalVar = !
in func2, globalVar = ?
=====================
似乎是 multiprocessing 有一份全局变量的原始备份,
在它被调用之前即使更改了全局变量的值,它也不更新