share dict between processes

前端 未结 2 1033
有刺的猬
有刺的猬 2020-12-19 20:09

I spawn a seperate process to handle my cloud services. I spawnb it like this:

CldProc = Process(target=CloudRun)
CldProc.start()

and am wo

相关标签:
2条回答
  • 2020-12-19 20:10

    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
    
    0 讨论(0)
  • 2020-12-19 20:15

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

    0 讨论(0)
提交回复
热议问题