[L14] Problem with futures and ProcessPoolExecutor

First of all, I’m very grateful for the precious insights this course has taught me. Thank you, thank you, thank you.

Now: I’m trying to run Tiramisu-Keras on my machine with Python 3.5.2 and the latest version of Keras. I have a problem with calling conv_all_labels(). It seems that my process pool breaks somehow: full error below.

It seems that an exception is raised… And I can’t figure out why. Any good samaritan around? :slight_smile:


BrokenProcessPool Traceback (most recent call last)
in ()

in conv_all_labels()
1 def conv_all_labels():
2 ex = ProcessPoolExecutor(8)
----> 3 return np.stack(ex.map(conv_one_label, range(n)))

c:\users\dade\appdata\local\programs\python\python35\lib\site-packages\numpy\core\shape_base.py in stack(arrays, axis)
346
347 “”"
–> 348 arrays = [asanyarray(arr) for arr in arrays]
349 if not arrays:
350 raise ValueError(‘need at least one array to stack’)

c:\users\dade\appdata\local\programs\python\python35\lib\site-packages\numpy\core\shape_base.py in (.0)
346
347 “”"
–> 348 arrays = [asanyarray(arr) for arr in arrays]
349 if not arrays:
350 raise ValueError(‘need at least one array to stack’)

c:\users\dade\appdata\local\programs\python\python35\lib\concurrent\futures_base.py in result_iterator()
554 for future in fs:
555 if timeout is None:
–> 556 yield future.result()
557 else:
558 yield future.result(end_time - time.time())

c:\users\dade\appdata\local\programs\python\python35\lib\concurrent\futures_base.py in result(self, timeout)
403 raise CancelledError()
404 elif self._state == FINISHED:
–> 405 return self.__get_result()
406 else:
407 raise TimeoutError()

c:\users\dade\appdata\local\programs\python\python35\lib\concurrent\futures_base.py in __get_result(self)
355 def __get_result(self):
356 if self._exception:
–> 357 raise self._exception
358 else:
359 return self._result

BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.

Might this be the reason?

Having the same problem with a different function from fastai.text

2 Likes

I changed the function as shown below and it works. It was a post in this Forum it worked. I think nok was the author of this.

def parallel_trees(m, fn, n_jobs=8):
return list(ThreadPoolExecutor(n_jobs).map(fn, m.estimators_))

4 Likes

I am also facing the same problem with a different function from fastai
Any suggestion @lesscomfortable to fix this issue?

def get_preds(t): return t.predict(X_valid)
%time preds = np.stack(parallel_trees(m, get_preds))
np.mean(preds[:,0]), np.std(preds[:,0])

Thanks,
Ritika Agarwal

Thanks a lot bro!

Use the hack provided by Amol.

Regards

BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.

In my case it was the parallel function that could work only with max_workers=1

1 Like