<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import ipyparallel as ipp <EOL> from joblib . _parallel_backends import ParallelBackendBase , AutoBatchingMixin <EOL> class IPythonParallelBackend ( AutoBatchingMixin , ParallelBackendBase ) : <EOL> def __init__ ( self , view = None ) : <EOL> if view is None : <EOL> self . _owner = True <EOL> rc = ipp . Client ( ) <EOL> view = rc . load_balanced_view ( ) <EOL> try : <EOL> import cloudpickle <EOL> except ImportError : <EOL> try : <EOL> import dill <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> view . client [ : ] . use_dill ( ) <EOL> else : <EOL> view . client [ : ] . use_cloudpickle ( ) <EOL> else : <EOL> self . _owner = False <EOL> self . _view = view <EOL> def effective_n_jobs ( self , n_jobs ) : <EOL> """<STR_LIT>""" <EOL> return len ( self . _view ) <EOL> def terminate ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _owner : <EOL> self . _view . client . close ( ) <EOL> def apply_async ( self , func , callback = None ) : <EOL> """<STR_LIT>""" <EOL> future = self . _view . apply_async ( func ) <EOL> if callback : <EOL> future . add_done_callback ( lambda f : callback ( f . result ( ) ) ) <EOL> return future </s>
