@contextmanager
def parallel_backend(backend, n_jobs=(-1), **backend_params):
 if isinstance(backend, _basestring):
  backend = BACKENDS[backend](**backend_params)
 old_backend_and_jobs = getattr(_backend, 'backend_and_jobs', None)
 try:
  _backend.backend_and_jobs = (backend, n_jobs)
  (yield (backend, n_jobs))
 finally:
  if (old_backend_and_jobs is None):
   if (getattr(_backend, 'backend_and_jobs', None) is not None):
    del _backend.backend_and_jobs
  else:
   _backend.backend_and_jobs = old_backend_and_jobs

@ contextmanager def parallel_backend ( backend , n_jobs = ( - 1 ) , ** backend_params ) : if isinstance ( backend , _basestring ) : backend = BACKENDS [ backend ] ( ** backend_params ) old_backend_and_jobs = getattr ( _backend , 'backend_and_jobs' , None ) try : _backend . backend_and_jobs = ( backend , n_jobs ) ( yield ( backend , n_jobs ) ) finally : if ( old_backend_and_jobs is None ) : if ( getattr ( _backend , 'backend_and_jobs' , None ) is not None ) : del _backend . backend_and_jobs else : _backend . backend_and_jobs = old_backend_and_jobs
change the default backend used by parallel inside a with block .