a
    feza
                  	   @   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 zddl	Z
dd
dZW n eyj   dddZY n0 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 d|t| t  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_collectZmmr    r   /lib/python3.9/site-packages/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}||k r|zt | | W q~W q tyx } z:t|ddtv rbt| ||7 }|d9 }n W Y d}~qd}~0 0 q 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)__doc__r   r$   Zdistutils.versionr   Zos.pathr   Zmultiprocessingr   Znumpyr   r   ImportErrornamer#   r   r)   r   r   r   r   <module>   s&       

