a
    xdY                     @   sd   d dl Z d dlZd dlZd dlZd dlZd dlZG dd deZG dd deZ	G dd de
ZdS )    Nc                   @   s   e Zd ZdS )MaxFailuresErrorN__name__
__module____qualname__ r   r   P/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/lit/run.pyr   
   s   r   c                   @   s   e Zd ZdS )TimeoutErrorNr   r   r   r   r   r	      s   r	   c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )Runz#A concrete, configured testing run.c                 C   s4   || _ || _|| _|| _|| _|| _|dks0J d S )Nr   )tests
lit_configworkersprogress_callbackmax_failurestimeout)selfr   r   r   r   r   r   r   r   r   __init__   s    zRun.__init__c              
   C   s   d| _ d}| jp|}t | }z>| | W tjtjj}| jD ]}|j	du rD|
| qDn2tjtjj}| jD ]}|j	du rv|
| qv0 dS )a  
        Execute the tests in the run using up to the specified number of
        parallel tasks, and inform the caller of each individual result. The
        provided tests should be a subset of the tests available in this run
        object.

        The progress_callback will be invoked for each completed test.

        If timeout is non-None, it should be a time in seconds after which to
        stop executing tests.

        Returns the elapsed testing time.

        Upon completion, each test in the run will have its result
        computed. Tests which were not actually executed (for any reason) will
        be marked SKIPPED.
        r   i:	 N)failuresr   time_executelitZTestResultZSKIPPEDr   resultZ	setResult)r   Zone_weekr   deadlineskippedtestr   r   r   execute   s    




zRun.executec                    s      dd jj D }tjtjj	j|f  fddj
D }   z4z|| W n       Y n0 W    n
   0 d S )Nc                 S   s$   i | ]\}}|d ur|t |qS N)multiprocessingBoundedSemaphore).0kvr   r   r   
<dictcomp>A   s   z Run._execute.<locals>.<dictcomp>c                    s$   g | ]} j tjj|gjd qS ))argscallback)Zapply_asyncr   workerr   r   )r    r   poolr   r   r   
<listcomp>H   s   z Run._execute.<locals>.<listcomp>)_increase_process_limitr   Zparallelism_groupsitemsr   ZPoolr   r   r&   Z
initializer   close	_wait_for	terminatejoin)r   r   Z
semaphoresasync_resultsr   r'   r   r   >   s"    

zRun._executec              	   C   s   |t    }t|D ]l\}}z||}W n tjyD   t Y q0 | | j| | | r|  jd7  _| j| j	krt
 qd S )N   )r   	enumerategetr   r	   _update_testr   Z	isFailurer   r   r   )r   r0   r   r   idxarr   r   r   r   r-   V   s    zRun._wait_forc                 C   s   |j |_ |j|_d S r   )requiresr   )r   
local_testZremote_testr   r   r   r4   g   s    zRun._update_testc              
   C   s   t j }| j| d }zVdd l}|j}||\}}t||}||k rl||||f | j	
d||f  W n> ty } z&tjdkr| j	d|  W Y d }~n
d }~0 0 d S )N   r   z"Raised process limit from %d to %dntz!Failed to raise process limit: %s)r   utilZusable_core_countr   resourceZRLIMIT_NPROCZ	getrlimitminZ	setrlimitr   Znote	Exceptionosnamewarning)r   ZncpusZdesired_limitr<   ZNPROCZ
soft_limitZ
hard_limitexr   r   r   r*   p   s    



zRun._increase_process_limitN)
r   r   r   __doc__r   r   r   r-   r4   r*   r   r   r   r   r
      s   
!	r
   )r   r?   r   Zlit.Testr   Zlit.utilZ
lit.workerr>   r   r	   objectr
   r   r   r   r   <module>   s   