Skip to content

Commit

Permalink
testing.CrossValidation & co.: use forkserver process start method on…
Browse files Browse the repository at this point in the history
… OS X
  • Loading branch information
kernc committed Apr 21, 2016
1 parent ab9ce76 commit 26a12c8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Orange/evaluation/testing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import multiprocessing as mp
from itertools import product
from threading import Thread
Expand All @@ -19,10 +20,14 @@
__all__ = ["Results", "CrossValidation", "LeaveOneOut", "TestOnTrainingData",
"ShuffleSplit", "TestOnTestData", "sample"]


# Workaround for locks on Macintosh
# https://pythonhosted.org/joblib/parallel.html#bad-interaction-of-multiprocessing-and-third-party-libraries
MP_CONTEXT = mp.get_context('forkserver' if sys.platform == 'darwin' else None)

mp_result = namedtuple('mp_result', ('fold_idx', 'learner_idx', 'model',
'failed', 'n_values', 'values', 'probs'))


def _identity(x):
return x

Expand Down Expand Up @@ -349,7 +354,7 @@ def _callback_percent(n_steps, queue):
self._callback(percent)

results = []
with joblib.Parallel(n_jobs=n_jobs) as parallel:
with joblib.Parallel(n_jobs=n_jobs, backend=MP_CONTEXT) as parallel:
tasks = (joblib.delayed(_mp_worker)(*args) for args in args_iter)
thread = Thread(target=lambda: results.append(parallel(tasks)))
thread.start()
Expand Down

0 comments on commit 26a12c8

Please sign in to comment.