def parallel_func(func, n_jobs, verbose=5):
 try:
  try:
   from joblib import Parallel, delayed
  except ImportError:
   from sklearn.externals.joblib import Parallel, delayed
  parallel = Parallel(n_jobs, verbose=verbose)
  my_func = delayed(func)
  if (n_jobs == (-1)):
   try:
    import multiprocessing
    n_jobs = multiprocessing.cpu_count()
   except (ImportError, NotImplementedError):
    import warnings
    warnings.warn(module_unavailable_doc.format('multiprocessing'), ModuleUnavailableWarning)
    n_jobs = 1
 except ImportError:
  import warnings
  warnings.warn(module_unavailable_doc.format('joblib'), ModuleUnavailableWarning)
  n_jobs = 1
  my_func = func
  parallel = list
 return (parallel, my_func, n_jobs)

def parallel_func ( func , n_jobs , verbose = 5 ) : try : try : from joblib import Parallel , delayed except ImportError : from sklearn . externals . joblib import Parallel , delayed parallel = Parallel ( n_jobs , verbose = verbose ) my_func = delayed ( func ) if ( n_jobs == ( - 1 ) ) : try : import multiprocessing n_jobs = multiprocessing . cpu_count ( ) except ( ImportError , NotImplementedError ) : import warnings warnings . warn ( module_unavailable_doc . format ( 'multiprocessing' ) , ModuleUnavailableWarning ) n_jobs = 1 except ImportError : import warnings warnings . warn ( module_unavailable_doc . format ( 'joblib' ) , ModuleUnavailableWarning ) n_jobs = 1 my_func = func parallel = list return ( parallel , my_func , n_jobs )
return parallel instance with delayed function util function to use joblib only if available parameters func: callable a function n_jobs: int number of jobs to run in parallel verbose: int verbosity level returns parallel: instance of joblib .