o
    l¨Êh  ã                   @   s`  d Z ddlZddlZddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZmZ zddlZW n ey?   dZY nw z
ddlZdd„ ZW n eyY   dd„ ZdZY nw zdd	lmZ d
d„ Zdd„ ZW n ey{   dd„ Zd ZZY nw eƒ Zddd„Zdd„ Zee
du dd�Zeej d¡ dd�Zeedu p¢e dd�Zeedudd�Z dS )z
Small utilities for testing.
é    N)ÚPY3_OR_LATER)Úmp)ÚSkipTestÚskipifc                 C   ó   | S )ú*A decorator to skip tests requiring numpy.© ©Úfuncr   r   úD/var/www/html/env/lib/python3.10/site-packages/joblib/test/common.pyÚ
with_numpy   ó   r   c                 C   ó   dd„ }|S )r   c                   S   ó   t dƒ‚)NzTest requires numpy©r   r   r   r   r   Úmy_func   ó   zwith_numpy.<locals>.my_funcr   )r
   r   r   r   r   r      ó   )Úmemory_usagec                 C   r   )ú4A decorator to skip tests requiring memory_profiler.r   r	   r   r   r   Úwith_memory_profiler+   r   r   c                 O   s*   t  ¡  t| ||fdd�}t|ƒt|ƒ S )z)Compute memory usage when executing func.gü©ñÒMbP?)Úinterval)ÚgcÚcollectr   ÚmaxÚmin)r
   ÚargsÚkwargsÚmem_user   r   r   Úmemory_used/   s   r   c                 C   r   )r   c                   S   r   )NzTest requires memory_profiler.r   r   r   r   r   Ú
dummy_func8   r   z(with_memory_profiler.<locals>.dummy_funcr   )r
   r    r   r   r   r   6   r   é   c                 C   sH   dt jv s
dtjv rdS t| ƒ dd„ }t ||¡ t| < }| ¡  dS )z±Timeout based suiciding thread to kill the test runner process

    If some subprocess dies in an unexpected way we don't want the
    parent process to block indefinitely.
    ÚNO_AUTOKILLz--pdbNc                  S   sJ   t  ¡ } td|  ƒ t  | tj¡ t d¡ td|  ƒ t  | tj¡ d S )Nz1Timeout exceeded: terminating stalled process: %dg      à?z-Timeout exceeded: killing stalled process: %d)	ÚosÚgetpidÚprintÚkillÚsignalÚSIGTERMÚtimeÚsleepÚSIGKILL)Úpidr   r   r   ÚautokillS   s   
z setup_autokill.<locals>.autokill)	r#   ÚenvironÚsysÚargvÚteardown_autokillÚ	threadingÚTimerÚ_KILLER_THREADSÚstart)Úmodule_nameÚtimeoutr-   Útr   r   r   Úsetup_autokillE   s   
r9   c                 C   s"   t  | ¡}|dur| ¡  dS dS )z)Cancel a previously started killer threadN)r4   ÚgetÚcancel)r6   Úkillerr   r   r   r1   a   s   
ÿr1   zNeeds multiprocessing to run.)Úreasonz/dev/shmz5This test requires a large /dev/shm shared memory fs.zNeeds lz4 compression to runz$Needs lz4 not being installed to run)r!   )!Ú__doc__r2   r'   r)   r#   r/   r   Újoblib._compatr   Újoblib._multiprocessing_helpersr   Újoblib.testingr   r   Úlz4ÚImportErrorÚnumpyÚnpr   Úmemory_profilerr   r   r   Údictr4   r9   r1   Úwith_multiprocessingÚpathÚexistsÚwith_dev_shmÚwith_lz4Úwithout_lz4r   r   r   r   Ú<module>   s\    ÿúù
ÿþÿ
ÿ