Can't pickle when using multiprocessing Pool.map()

后端 未结 12 2036
醉梦人生
醉梦人生 2020-11-22 00:19

I\'m trying to use multiprocessing\'s Pool.map() function to divide out work simultaneously. When I use the following code, it works fine:

12条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-22 01:22

    I ran into this same issue but found out that there is a JSON encoder that can be used to move these objects between processes.

    from pyVmomi.VmomiSupport import VmomiJSONEncoder
    

    Use this to create your list:

    jsonSerialized = json.dumps(pfVmomiObj, cls=VmomiJSONEncoder)
    

    Then in the mapped function, use this to recover the object:

    pfVmomiObj = json.loads(jsonSerialized)
    

提交回复
热议问题