B
    td                 @   sT  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 yddlZW n ek
rt   dZY nX yddlZdd ZW n  ek
r   dd ZdZY nX y ddlmZ d	d
 Zdd ZW n$ ek
r   dd
 Zd ZZY nX e ZdddZdd ZeedkddZeejd ddZeedkddZeedk	ddZdS )z
Small utilities for testing.
    N)mp)SkipTestskipifc             C   s   | S )z*A decorator to skip tests requiring numpy. )funcr   r   _/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/joblib/test/common.py
with_numpy   s    r   c             C   s   dd }|S )z*A decorator to skip tests requiring numpy.c               S   s   t dd S )NzTest requires numpy)r   r   r   r   r   my_func   s    zwith_numpy.<locals>.my_funcr   )r   r	   r   r   r   r      s    )memory_usagec             C   s   | S )z4A decorator to skip tests requiring memory_profiler.r   )r   r   r   r   with_memory_profiler*   s    r   c             O   s*   t   t| ||fdd}t|t| S )z)Compute memory usage when executing func.gMbP?)interval)gcZcollectr
   maxmin)r   argskwargsZmem_user   r   r   memory_used.   s    r   c             C   s   dd }|S )z4A decorator to skip tests requiring memory_profiler.c               S   s   t dd S )NzTest requires memory_profiler.)r   r   r   r   r   
dummy_func7   s    z(with_memory_profiler.<locals>.dummy_funcr   )r   r   r   r   r   r   5   s       c             C   sH   dt jksdtjk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.
    Z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    
r+   c             C   s   t | }|dk	r|  dS )z)Cancel a previously started killer threadN)r&   getcancel)r(   Zkillerr   r   r   r#   `   s    
r#   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__r$   r   r   r   r!   r   Zjoblib._multiprocessing_helpersr   Zjoblib.testingr   r   Zlz4ImportErrornumpynpr   Zmemory_profilerr
   r   r   dictr&   r+   r#   Zwith_multiprocessingpathexistsZwith_dev_shmZwith_lz4Zwithout_lz4r   r   r   r   <module>   sH   


