Skip to content Skip to sidebar Skip to footer

Share Dict Between Processes

I spawn a seperate process to handle my cloud services. I spawnb it like this: CldProc = Process(target=CloudRun) CldProc.start() and am wondering if I can have a shared dictionar

Solution 1:

Got it, to simplify, I did it like this:

from multiprocessing import Process, Manager

def myf(myd):
    myd[1] = "HELLO WORLD!"

def proc(d):
    myf(d)

m=Manager()
locdict=m.dict()
locdict[2] = "HI BUDDY!"

p = Process(target=proc, args=(locdict,))

p.start()
p.join()
print locdict

Solution 2:

Take a look at multiprocessing.Manager and the Manager.dict() method in particular. They may serve your needs.

Post a Comment for "Share Dict Between Processes"