Python Multiprocessing Pool Map: AttributeError: Can't pickle local object

前端 未结 2 2041
无人共我
无人共我 2020-12-01 11:42

I have a method inside a class that needs to do a lot of work in a loop, and I would like to spread the work over all of my cores.

I wrote the following code, which

2条回答
  •  北海茫月
    2020-12-01 12:14

    I accidentally discovered a very nasty solution. It works, as long as you use a def statement. If you declare the function, that you want to use in Pool.map with the global keyword at the beginning of the function that solves it. But I would not rely on this in serious applications

提交回复
热议问题