fork(2) download
  1. import multiprocessing
  2.  
  3. def init_pool(the_int):
  4. global GlobalVar
  5. GlobalVar = the_int
  6.  
  7. def f(x):
  8. return x**GlobalVar
  9.  
  10. if __name__ == '__main__':
  11. GlobalVar = 6
  12. pool = multiprocessing.Pool(initializer=init_pool, initargs=(GlobalVar,))
  13. res= pool.map(f,[1,2,3,4])
  14. print(res)
Success #stdin #stdout 0.13s 12888KB
stdin
Standard input is empty
stdout
[1, 64, 729, 4096]