HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //proc/1233/cwd/usr/lib/python3/dist-packages/compose/__pycache__/parallel.cpython-310.pyc
o

S�`,-�@s�ddlZddlZddlZddlZddlmZddlmZddlm	Z	ddlm
Z
ddlmZddlm
Z
ddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZe�e�Ze�Z Gdd�d�Z!dd�Z"d2dd�Z#dd�Z$Gdd�d�Z%Gdd�d�Z&dd�Z'd d!�Z(d"d#�Z)Gd$d%�d%e*�Z+Gd&d'�d'�Z,d(d)�Z-d*d+�Z.d,d-�Z/d.d/�Z0d0d1�Z1dS)3�N)�Empty)�Queue)�Lock)�	Semaphore)�Thread)�APIError)�
ImageNotFound)�AnsiMode)�green)�red)�ShutdownException)�PARALLEL_LIMIT)�CompletedUnsuccessfully)�HealthCheckFailed)�NoHealthCheckConfigured)�OperationFailedErrorc@s$eZdZdZee�Zedd��ZdS)�GlobalLimitz�Simple class to hold a global semaphore limiter for a project. This class
    should be treated as a singleton that is instantiated when the project is.
    cCs|durt}t|�|_dS�N)r
r�global_limiter)�cls�value�r�2/usr/lib/python3/dist-packages/compose/parallel.py�set_global_limit%szGlobalLimit.set_global_limitN)	�__name__�
__module__�__qualname__�__doc__rr
r�classmethodrrrrrrs
rcCs,d}|D]�\}}	}
|
dur0|dur ||�r |�|||�dt�n
|�|||�dt�|�|	�qt|
t�rI|
j|||�<|�|||�dt�|
}qt|
t�r`|
j|||�<|�|||�dt�qt|
tt	t
tf�r{|
j|||�<|�|||�dt�qt|
t
�r�|�|||�dt�q|
|||�<|
}q|S)z Watch events from a parallel execution, update status and fill errors and results.
        Returns exception to re-raise.
    N�failed�done�error)�writerr
�append�
isinstancer�explanationrrrrr�msg�
UpstreamError)�events�writer�errors�resultsr&�get_name�
fail_check�error_to_reraise�obj�result�	exceptionrrr�parallel_execute_watch,s0


�
r2cCs�t|�}tj}t�t|��}|D]
}	|�|||	��q|D]
}	|�|||	��qt||||�}
i}g}t|
||||||�}
|�	�D]
\}}|�
d�||��qA|
rS|
�||fS)a�Runs func on objects in parallel while ensuring that func is
    ran on object only after it is ran on all its dependencies.

    get_deps called on object must return a collection with its dependencies.
    get_name called on object must return its name.
    fail_check is an additional failure check for cases that should display as a failure
        in the CLI logs, but don't raise an exception (such as attempting to start 0 containers)
    z
ERROR: for {}  {}
)�list�sys�stderr�ParallelStreamWriter�get_or_assign_instance�
add_object�
write_initial�parallel_execute_iterr2�itemsr"�format)�objects�funcr,r&�get_deps�limitr-�streamr)r/r(r*r+r.�obj_namer!rrr�parallel_executeMs$	�rCcCsgSrr)�xrrr�_no_depsq�rEc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�Statez�
    Holds the state of a partially-complete parallel operation.

    state.started:   objects being processed
    state.finished:  objects which have been processed
    state.failed:    objects which either failed or whose dependencies failed
    cCs"||_t�|_t�|_t�|_dSr)r=�set�started�finishedr)�selfr=rrr�__init__}szState.__init__cCst|j�t|j�t|j�kSr)�lenrJrr=�rKrrr�is_done�sz
State.is_donecCst|j�|j|j|jSr)rHr=rIrJrrNrrr�pending�sz
State.pendingN)rrrrrLrOrPrrrrrGus
rGc@seZdZdd�Zdd�ZdS)�NoLimitcC�dSrrrNrrr�	__enter__�rFzNoLimit.__enter__cGrRrr)rK�exrrr�__exit__�rFzNoLimit.__exit__N)rrrrSrUrrrrrQ�srQccs��|durt}|durt�}nt|�}t�}t|�}	t||||||�z|jdd�}Wnty5Yqtj	y?t
��w|turFdS|\}}	}
|
dur^t�
d�|��|j�|�nt�
d�|��|j�|�|Vq)a�
    Runs func on objects in parallel while ensuring that func is
    ran on object only after it is ran on all its dependencies.

    Returns an iterator of tuples which look like:

    # if func returned normally when run on object
    (object, result, None)

    # if func raised an exception when run on object
    (object, None, exception)

    # if func raised an exception when run on one of object's dependencies
    (object, None, UpstreamError())
    NTg�������?)�timeoutzFinished processing: {}z
Failed: {})rErQrrrG�
feed_queue�getr�threadr!r�STOP�log�debugr<rJ�addr)r=r>r?r@�limiterr+�state�eventr/�_r1rrrr:�s6��
�r:cCs�|�Mtj�1z||�}|�||df�Wnty/}z|�|d|f�WYd}~nd}~wwWd�n1s:wYWd�dSWd�dS1sRwYdS)z�
    The entry point for a producer thread which runs func on a single object.
    Places a tuple on the results queue once func has either returned or raised.
    N)rr�put�	Exception)r/r>r+r^r0�errr�producer�s���P�recsn���}t�d�|��|D]�}||�}zPt�fdd�|D��r8t�d�|��|�|dt�f��j�|�n+t	��fdd�|D��rct�d�|��t
t||||fd�}	d	|	_|	�
��j�|�Wqttfy�}
zt�d
�|��|�|d|
f�WYd}
~
qd}
~
wty�}
zt�d�|��|�|d|
f�WYd}
~
qd}
~
ww���r�|�t�dSdS)a)
    Starts producer threads for any objects which are ready to be processed
    (i.e. they have no dependencies which haven't been successfully processed).

    Shortcuts any objects whose dependencies have failed and places an
    (object, None, UpstreamError()) tuple on the results queue.
    zPending: {}c3s�|]
}|d�jvVqdS)rN)r)�.0�dep)r_rr�	<genexpr>�s�zfeed_queue.<locals>.<genexpr>z'{} has upstream errors - not processingNc3s4�|]\}}|�vp|�jvo|p||�VqdSr)rJ)rfrg�ready_check�r=r_rrrh�s��
�zStarting producer thread for {})�target�argsTzAHealthcheck for service(s) upstream of {} failed - not processingzIService(s) upstream of {} did not completed successfully - not processing)rPr[r\r<�anyrbr'rr]�allrre�daemon�startrIrrrrOrZ)r=r>r?r+r_r^rPr/�deps�trdrrjrrW�sH��������rWc@seZdZdS)r'N)rrrrrrrr'sr'c@s|eZdZdZejZe�ZdZ	e�Z
edd��Zedd��Z
edd��Zdd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�ZdS)r6z�Write out messages for operations happening in parallel.

    Each operation has its own line, and ANSI code characters are used
    to jump to the correct line, and write over the line.
    NcCs|jSr)�instance)rrrr�get_instancesz!ParallelStreamWriter.get_instancecCs:|j��z|jdur||_|jW|j��S|j��wr)�
instance_lock�acquirers�release)rr)rrrr7s

z+ParallelStreamWriter.get_or_assign_instancecCs
||_dSr)�default_ansi_mode)r�	ansi_moderrr�set_default_ansi_mode s
z*ParallelStreamWriter.set_default_ansi_modecCs0|dur|j}||_|�|�|_g|_d|_dS)Nr)rxrA�use_ansi_codes�lines�width)rKrAryrrrrL$s
zParallelStreamWriter.__init__cCs:|durdS|j�||�t|jt|d|��|_dS)N� )r|r#�maxr}rM�rKr&�	obj_indexrrrr8,szParallelStreamWriter.add_objectcCs|durdS|�||d�S)N�)�
_write_noansir�rrrr92sz"ParallelStreamWriter.write_initialcCs�|j��|j�||�}t|j�|}|j�dd|f�|j�dd�|j�dj|d|||jd��|j�dd|f�|j�	�|j�
�dS)Nz%c[%dA�z%c[2K
z{:<{width}} ... {}
r~�r}z%c[%dB)�
write_lockrvr|�indexrMrAr"r<r}�flushrw)rKr&r��status�position�diffrrr�_write_ansi7s
�
z ParallelStreamWriter._write_ansicCs0|j�dj|d|||jd��|j��dS)Nz{:<{width}} ... {}
r~r�)rAr"r<r}r�)rKr&r�r�rrrr�Fs��z"ParallelStreamWriter._write_noansicCs:|durdS|jr|�||||��dS|�|||�dSr)r{r�r�)rKr&r�r��
color_funcrrrr"Ns
zParallelStreamWriter.writer)rrrrr	�AUTOrxrr�rsrurrtr7rzrLr8r9r�r�r"rrrrr6s$

	

r6cCs&t|tj|fi|��t�d�|�dS)N�name)rC�operator�methodcaller�
attrgetter)�
containers�	operation�options�messagerrr�parallel_operationWs�r�cCs dd�|D�}t|d|d�dS)NcSsg|]}|js|�qSr)�
is_running)rf�crrr�
<listcomp>asz#parallel_remove.<locals>.<listcomp>�remove�Removing�r�)r�r��stopped_containersrrr�parallel_remove`sr�cC�t|d|d�dS)N�pause�Pausingr��r�r�rrr�parallel_pausee�r�cCr�)N�unpause�	Unpausingr�r�rrr�parallel_unpauseir�r�cCr�)N�kill�Killingr�r�rrr�
parallel_killmr�r�)NNN)2�_threadrY�loggingr�r4�queuerr�	threadingrrr�
docker.errorsrr�compose.cli.colorsr	r
r�compose.cli.signalsr�
compose.constr
�compose.errorsrrrr�	getLoggerrr[�objectrZrr2rCrErGrQr:rerWrcr'r6r�r�r�r�r�rrrr�<module>sL

!$4
-R