3
d
                 @   s   d Z ddlZddlZddlmZ ddlmZ ddlmZ yddl	Z
dd
dZW n ek
rl   dddZY nX ejdkrdZddlmZ dd ZnddlmZ dS )z,
Backports of fixes for joblib dependencies
    N)LooseVersion)basename)utiluint8r+CFc       	      C   sb   t jdj|t| tj  tj| |||||d}ttj	dk rF||_
|r^ddlm} || |S )ab  Custom memmap constructor compatible with numpy.memmap.

        This function:
        - is a backport the numpy memmap offset fix (See
          https://github.com/numpy/numpy/pull/8443 for more details.
          The numpy fix is available starting numpy 1.13)
        - adds ``unlink_on_gc_collect``, which specifies  explicitly whether
          the process re-constructing the memmap owns a reference to the
          underlying file. If set to True, it adds a finalizer to the
          newly-created memmap that sends a maybe_unlink request for the
          memmaped file to resource_tracker.
        z?[MEMMAP READ] creating a memmap (shape {}, filename {}, pid {}))dtypemodeoffsetshapeorderz1.13   )add_maybe_unlink_finalizer)r   debugformatr   osgetpidnpZmemmapr   __version__r
   Z_memmapping_reducerr   )	filenamer   r	   r
   r   r   unlink_on_gc_collectmmr    r   2/tmp/pip-build-v9q4h5k9/joblib/joblib/backports.pymake_memmap   s    
r   c             C   s   t dd S )NzL'joblib.backports.make_memmap' should not be used if numpy is not installed.)NotImplementedError)r   r   r	   r
   r   r   r   r   r   r   r   +   s    nt      )replacec             C   s   d}d}d}xp||k rzyt | | P W q tk
rv } z4t|ddtkrdtj| ||7 }|d9 }n W Y dd}~X qX qW  dS )zRenames ``src`` into ``dst`` overwriting ``dst`` if it exists.

        On Windows os.replace can yield permission errors if executed by two
        different processes.
        r   r   gMbP?winerrorN   )r   	Exceptiongetattraccess_denied_errorstimesleep)srcdstZmax_sleep_timeZtotal_sleep_timeZ
sleep_timeexcr   r   r   concurrency_safe_rename7   s    



r*   )r   r   r   Nr   F)r   r   r   Nr   F)r   r   )__doc__r   r%   Zdistutils.versionr   os.pathr   multiprocessingr   Znumpyr   r   ImportErrornamer$   r   r*   r   r   r   r   <module>   s"     

