I'm trying to parallelize with multiprocessing.Pool()
some processes that involve queries of R-trees. In the non-parallel procedure, it works as expected.
But when I try to do it in parallel (even with an example of running only 1 process in 1 core) the same query returns empty results.
I'm really puzzled about this, it goes beyond any logic for my understanding.
EDIT
Here is the simplest example that I could reproduce:
from multiprocess.pool import Pool
from rtree import index
class Test(object):
def __init__(self):
self.idx = index.Index()
left, bottom, right, top = (0.0, 0.0, 10.0, 10.0)
self.idx.insert(0, (left, bottom, right, top))
def test(self, a):
print(list(self.idx.intersection((1.0, 1.0, 2.0, 2.0))))
b = Test()
p = Pool()
res = p.map(b.test, range(3))
b.test(1)
output:
[]
[]
[]
[0]
list(idx.intersection(big_pol.bounds))
, and I use Python'sRtree
andmultiprocessing.Pool()
. The index is not passed as a parameter, so there is no problem with pickle.