o
    tBh                     @   sN  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
mZ zddlZW n ey9   dZY nw z
ddlZdd ZW n eyS   dd ZdZY nw zddlmZ d	d
 Zdd ZW n eyu   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 ddZeeduddZdS )z
Small utilities for testing.
    N)mp)SkipTestskipifc                 C      | S )*A decorator to skip tests requiring numpy. funcr   r   i/var/www/html/riverr-enterprise-integrations-main/venv/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.gMbP?)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_func7   r   z(with_memory_profiler.<locals>.dummy_funcr   )r	   r   r   r   r
   r   5   r      c                 C   sH   dt jv s
dtjv rdS t|  dd }t|| t| < }|  dS )zTimeout 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
   autokillR   s   
z setup_autokill.<locals>.autokill)	r"   environsysargvteardown_autokill	threadingTimer_KILLER_THREADSstart)module_nametimeoutr,   tr   r   r
   setup_autokillD   s   
r8   c                 C   s"   t | }|dur|  dS dS )z)Cancel a previously started killer threadN)r3   getcancel)r5   killerr   r   r
   r0   `   s   
r0   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__r1   r&   r(   r"   r.   r   joblib._multiprocessing_helpersr   joblib.testingr   r   lz4ImportErrornumpynpr   memory_profilerr   r   r   dictr3   r8   r0   with_multiprocessingpathexistswith_dev_shmwith_lz4without_lz4r   r   r   r
   <module>   sV    

