
    Vh$
                    4   U d Z ddlmZ ddlm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 ej                  dej                  dej                  f         Z G d de	j"                        Zdd	Z e	j(                         Zi Zd
ed<   ej0                  dd       Zy)zPython threading tools.    )annotationsN	TCallable.)boundc                  4     e Zd ZdZd fdZddZddZ xZS )WrappedThreadz<Wrapper around Thread which captures results and exceptions.c                p    t         |           t        j                         | _        || _        d | _        y )N)super__init__queueQueue_resultactionresult)selfr   	__class__s     M/home/dcms/DCMS/lib/python3.12/site-packages/ansible_test/_internal/thread.pyr
   zWrappedThread.__init__   s)    +0;;=    c                    	 | j                   j                  | j                         df       y#  | j                   j                  dt        j                         f       Y yxY w)z
        Run action and capture results or exception.
        Do not override. Do not call directly. Executed by the start() method.
        N)r   putr   sysexc_info)r   s    r   runzWrappedThread.run   sH    	5LLdkkmT23	5LLdCLLN34s	   +. 1A!c                    | j                   j                         \  }}|r|d   j                  |d         || _        |S )zDWait for thread to exit and return the result or raise an exception.      )r   getwith_tracebackr   )r   r   	exceptions      r   wait_for_resultzWrappedThread.wait_for_result'   sA     LL,,.	A,--il;;r   )r   zc.Callable[[], t.Any]returnNone)r    r!   )r    zt.Any)__name__
__module____qualname____doc__r
   r   r   __classcell__)r   s   @r   r   r      s    F5	r   r   c                n     t        j                         t        j                          fd       }|S )z1Enforce exclusive access on a decorated function.c                 D    5   | i |cddd       S # 1 sw Y   yxY w)zTWrapper around `func` which uses a lock to provide exclusive access to the function.N )argskwargsfunclocks     r   wrapperzmutex.<locals>.wrapper7   s*      	)((	) 	) 	)s   )	threadingLock	functoolswraps)r,   r.   r-   s   ` @r   mutexr3   3   s1    >>D__T) )
 Nr   zdict[str, threading.Lock]__named_locksc              #     K   t         5  t        j                  |       x}rd}nd}t        j                         x}t        | <   ddd       5   ddd       y# 1 sw Y   xY w# 1 sw Y   yxY ww)z
    Context manager that provides named locks using threading.Lock instances.
    Once named lock instances are created they are not deleted.
    Returns True if this is the first instance of the named lock, otherwise False.
    FTN)__named_lockr4   r   r/   r0   )namelock_instancefirsts      r   
named_lockr:   D   s}      
 C)--d33=3EE2;..2BBMM$/C 
  C C s4   A3:A
A3A'	A3A$ A3'A0,A3)r,   r   r    r   )r7   strr    zc.Iterator[bool])r%   
__future__r   collections.abcabcc
contextlibr1   r   r/   r   typingtTypeVarCallableAnyr   Threadr   r3   r0   r6   r4   __annotations__contextmanagerr:   r)   r   r   <module>rI      s     "    
    AIIkCJ)?@	 I$$  F
 y~~+-( -  r   