snap-python icon indicating copy to clipboard operation
snap-python copied to clipboard

Parallel Error

Open Haicang opened this issue 7 years ago • 1 comments

This package is built on swig. But swigpyobject cannot be pickled, which makes it impossible to parallel on this package.

Haicang avatar Aug 21 '18 03:08 Haicang

Hi, I circumvented this limitation by exploiting the fact that in Unix the forking of the workers inherit the environment of the master process, including its data. What I do is to load the graph as a global variable first, before initialising the Pool, and then use it in the worker function as a global. The catch is that you can't modify the graph in parallel, the changes won't be seen in the master process. However you can compute things over the graph in parallel without a problem in read-only mode.

I made a gist with an example to compute node eccentricities in parallel here: https://gist.github.com/hhromic/2e93de406fb6b1e3de5f9ab6f5f84622 It is for python2 but is easy to adapt to python3 and the beta snap for python3.

Edit: just to make it clear, this won't work on Windows.

hhromic avatar Aug 22 '18 11:08 hhromic