

def parallel_func(func, n_jobs, verbose=5):
    'Return parallel instance with delayed function\n\n    Util function to use joblib only if available\n\n    Parameters\n    ----------\n    func: callable\n        A function\n    n_jobs: int\n        Number of jobs to run in parallel\n    verbose: int\n        Verbosity level\n\n    Returns\n    -------\n    parallel: instance of joblib.Parallel or list\n        The parallel object\n    my_func: callable\n        func if not parallel or delayed(func)\n    n_jobs: int\n        Number of jobs >= 0\n\n    Examples\n    --------\n    >>> from math import sqrt\n    >>> from statsmodels.tools.parallel import parallel_func\n    >>> parallel, p_func, n_jobs = parallel_func(sqrt, n_jobs=-1, verbose=0)\n    >>> print(n_jobs)\n    >>> parallel(p_func(i**2) for i in range(10))\n    '
    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, func)

dataset/ETHPy150Open statsmodels/statsmodels/statsmodels/tools/parallel.py parallel_func/VarMisuse@171/525 `n_jobs`->`func`