a
    xdj
                     @   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Zda	da
dd Zdd Zejdd Zd	d
 Zdd Zdd Zdd ZdS )a!  
The functions in this module are meant to run on a separate worker process.
Exception: in single process mode _execute is called directly.

For efficiency, we copy all data needed to execute all tests into each worker
and store it in global variables. This reduces the cost of each task.
    Nc                 C   s   | a |attjtj dS )z=Copy data shared by all test executions into worker processesN)_lit_config_parallelism_semaphoressignalSIGINTSIG_IGN)
lit_configZparallelism_semaphores r   S/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/lit/worker.py
initialize   s    r
   c                 C   s@   t |  t| t}W d   n1 s(0    Y  | | | S )zRun one test in a multiprocessing.Pool

    Side effects in this function and functions it calls are not visible in the
    main lit process.

    Arguments and results of this function are pickled, so they should be cheap
    to copy.
    N)_get_parallelism_semaphore_executer   Z	setResult)testresultr   r   r	   execute#   s    	
(
r   c                   c   s
   d V  d S Nr   r   r   r   r	   NopSemaphore4   s    r   c                 C   s&   | j j}t|r|| }t|t S r   )configZparallelism_groupcallabler   getr   )r   Zpgr   r   r	   r   9   s    r   c                 C   s4   t   }t| |}t   | |_||_t |_|S r   )time_execute_test_handle_errorselapsedstartosgetpidpid)r   r   r   r   r   r   r	   r   A   s    

r   c                 C   s^   z| j j| |}t|W S    |jr* d}|t 7 }|d7 }tj	tjj
| Y S 0 d S )Nz#Exception during script execution:

)r   Ztest_formatr   _adapt_resultdebug	traceback
format_exclitTestResultZ
UNRESOLVED)r   r   r   outputr   r   r	   r   J   s    
r   c                 C   s6   t | tjjr| S t | ts J | \}}tj||S r   )
isinstancer!   r"   r#   tuple)r   coder$   r   r   r	   r   Y   s
    r   )__doc__
contextlibr   r   r   r   Zlit.Testr!   Zlit.utilr   r   r
   r   contextmanagerr   r   r   r   r   r   r   r   r	   <module>   s"   
	