ó
‡ˆ\c           @   sq   d  Z  d d l Z d d l m Z d d l m Z d d l m Z d a	 d d d d „ Z
 d	 d d
 „  ƒ  YZ d S(   sÿ   Utility function to construct a loky.ReusableExecutor with custom pickler.

This module provides efficient ways of working with data stored in
shared memory with numpy.memmap arrays without inducing any memory
copy between the parent and child processes.
iÿÿÿÿNi   (   t   delete_folder(   t   get_memmapping_reducers(   t   get_reusable_executori,  c         K   s§   t  d
 k p t  | k } | a  t j d t d ƒ ƒ } t | |  \ } } }	 t |  d | d | d | d | d | d | ƒ}
 t |
 d	 ƒ s™ |	 |
 _ n
 t	 |	 ƒ |
 S(   sW   Factory for ReusableExecutor with automatic memmapping for large numpy
    arrays.
    i    g    _ Bt   job_reducerst   result_reducerst   reuset   timeoutt   initializert   initargst   _temp_folderN(
   t   _backend_argst   Nonet   randomt   randintt   intR   R   t   hasattrR	   R    (   t   n_jobsR   R   R   t   backend_argsR   t   id_executorR   R   t   temp_foldert	   _executor(    (    s@   lib/python2.7/site-packages/sklearn/externals/joblib/executor.pyt   get_memmapping_executor   s    	
t   _TestingMemmappingExecutorc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s~   Wrapper around ReusableExecutor to ease memmapping testing with Pool
    and Executor. This is only for testing purposes.
    c         K   s%   t  | |  |  _ |  j j |  _ d  S(   N(   R   R   R	   (   t   selfR   R   (    (    s@   lib/python2.7/site-packages/sklearn/externals/joblib/executor.pyt   __init__3   s    c         C   s%   |  j  j | | Œ } | j | _ | S(   s   Schedule a func to be run(   R   t   submitt   resultt   get(   R   t   funct   argst   future(    (    s@   lib/python2.7/site-packages/sklearn/externals/joblib/executor.pyt   apply_async7   s    c         C   s   |  j  j ƒ  t |  j ƒ d  S(   N(   R   t   shutdownR    R	   (   R   (    (    s@   lib/python2.7/site-packages/sklearn/externals/joblib/executor.pyt	   terminate=   s    c         G   s   |  j  j | | Œ } t | ƒ S(   N(   R   t   mapt   list(   R   t   fR   t   res(    (    s@   lib/python2.7/site-packages/sklearn/externals/joblib/executor.pyR"   A   s    (   t   __name__t
   __module__t   __doc__R   R   R!   R"   (    (    (    s@   lib/python2.7/site-packages/sklearn/externals/joblib/executor.pyR   /   s
   			(    (    (   R(   R   t   diskR    t   _memmapping_reducerR   t    externals.loky.reusable_executorR   R   R
   R   R   (    (    (    s@   lib/python2.7/site-packages/sklearn/externals/joblib/executor.pyt   <module>   s   