code: def _map_parallel(function, args, n_jobs):
      
      # Following the error checking found in joblib
      multiprocessing = int(os.environ.get('JOBLIB_MULTIPROCESSING', 1)) or None
      if multiprocessing:
          try:
              import multiprocessing
              import multiprocessing.pool
          except ImportError:
              multiprocessing = None
          if sys.platform.startswith("win") and PY2:
              msg = "Multiprocessing is not supported on Windows with Python 2.X. Setting n_jobs=1"
              logger.warning(msg)
              n_jobs = 1
      # 2nd stage: validate that locking is available on the system and
      #            issue a warning if not
      if multiprocessing:
          try:
              _sem = multiprocessing.Semaphore()
              del _sem  # cleanup
          except (ImportError, OSError) as e:
              multiprocessing = None
              logger.warning('{}. _map_parallel will operate in serial mode'.format(e))
      if multiprocessing and int(n_jobs) not in (0, 1):
          if n_jobs == -1:
              n_jobs = None
          try:
              pool = multiprocessing.Pool(processes=n_jobs)
              map_result = pool.map(function, args)
          finally:
              pool.close()
              pool.join()
      else:
          map_result = list(map(function, args))
      return map_result
docs: multiprocessing.Pool(processors=n_jobs).map with some error checking