§
    (¶ÕiH  ã                   óî   — 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 dlmZ d„ Z	d„ Z
d„ Zej        dd„¦   «         Zdd„Zej        dd„¦   «         Z G d	„ d
¦  «        Zdefd„Z e¦   «         Zddœd„ZdS )é    N)Úsupportc                  ód   — t          j        ¦   «         t          j                             ¦   «         fS ©N)Ú_threadÚ_countÚ	threadingÚ	_danglingÚcopy© ó    ú4/usr/lib/python3.11/test/support/threading_helper.pyÚthreading_setupr      s$   € ÝŒ>ÑÔ�YÔ0×5Ò5Ñ7Ô7Ð7Ð7r   c                  ó¸  — d}t          |¦  «        D ]Ç}t          j        ¦   «         t          j        f}|| k    r d S |srdt
          _        |d         }t          j        d|d         | d         z
  › d|d         › dt          |¦  «        › d�¦  «         |D ]}t          j        d	|›�¦  «         Œd }d }t          j
        d
¦  «         t          j        ¦   «          ŒÈd S )Néd   Té   z&threading_cleanup() failed to cleanup r   z threads (count: z, dangling: ú)zDangling thread: ç{®Gáz„?)Úranger   r   r   r	   r   Úenvironment_alteredÚprint_warningÚlenÚtimeÚsleepÚ
gc_collect)Úoriginal_valuesÚ
_MAX_COUNTÚcountÚvaluesÚdangling_threadsÚthreads         r   Úthreading_cleanupr!      s6  € Ø€Jå�zÑ"Ô"ð ð ˆÝ”Ñ!Ô!¥9Ô#6Ð6ˆØ�_Ò$Ð$ØˆEˆEàð 	$à*.�GÔ'Ø% aœyÐÝÔ!ð #HØ%+¨A¤Y°ÀÔ1CÑ%Cð#Hð #Hà-3°A¬Yð#Hð #Hõ 03Ð3CÑ/DÔ/Dð#Hð #Hð #Hñ Iô Ið Ið +ð Fð F�ÝÔ%Ð&D¸&Ð&DÐ&DÑEÔEÐEÐEð  $ÐØˆåŒ
�4ÑÔÐÝÔÑÔÐÐð+ð r   c                 óF   ‡ — t          j        ‰ ¦  «        ˆ fd„¦   «         }|S )zƒUse this function when threads are being used.  This will
    ensure that the threads are cleaned up even when the test fails.
    c                  óZ   •— t          ¦   «         }	  ‰| Ž t          |Ž  S # t          |Ž  w xY wr   )r   r!   )ÚargsÚkeyÚfuncs     €r   Ú	decoratorzreap_threads.<locals>.decorator;   s<   ø€ åÑÔˆð	$Ø�4˜�;å˜sÐ#Ð#Ð#øÕ˜sÐ#Ð#Ð#øøøs   ‘ Ÿ*)Ú	functoolsÚwraps)r&   r'   s   ` r   Úreap_threadsr*   7   s;   ø€ õ „_�TÑÔð$ð $ð $ð $ñ Ôð$ð Ðr   c              #   ó  K  — | €t           j        } t          j        ¦   «         }	 dV — t	          j        ¦   «         }|| z   }	 t          j        ¦   «         }||k    rdS t	          j        ¦   «         |k    r8t	          j        ¦   «         |z
  }d||z
  › d|d›d|› d|› d�	}t          |¦  «        ‚t	          j        d	¦  «         t          j        ¦   «          Œ’# t	          j        ¦   «         }|| z   }	 t          j        ¦   «         }||k    rnwt	          j        ¦   «         |k    r8t	          j        ¦   «         |z
  }d||z
  › d|d›d|› d|› d�	}t          |¦  «        ‚t	          j        d	¦  «         t          j        ¦   «          Œ‘w xY w)
aH  
    bpo-31234: Context manager to wait until all threads created in the with
    statement exit.

    Use _thread.count() to check if threads exited. Indirectly, wait until
    threads exit the internal t_bootstrap() C function of the _thread module.

    threading_setup() and threading_cleanup() are designed to emit a warning
    if a test leaves running threads in the background. This context manager
    is designed to cleanup threads started by the _thread.start_new_thread()
    which doesn't allow to wait for thread exit, whereas thread.Thread has a
    join() method.
    NTz!wait_threads() failed to cleanup z threads after ú.1fz seconds (count: z, old count: r   r   )	r   ÚSHORT_TIMEOUTr   r   r   Ú	monotonicÚAssertionErrorr   r   )ÚtimeoutÚ	old_countÚ
start_timeÚdeadliner   ÚdtÚmsgs          r   Úwait_threads_exitr6   E   s  è è € ð €ÝÔ'ˆÝ”Ñ Ô €Ið!Øˆˆˆå”^Ñ%Ô%ˆ
Ø Ñ'ˆð	!Ý”NÑ$Ô$ˆEØ˜	Ò!Ð!Ø�ÝŒ~ÑÔ (Ò*Ð*Ý”^Ñ%Ô%¨
Ñ2�ðC¸5À9Ñ;Lð Cð CØ(*Ð9ðCð Cà"'ðCð Cà6?ðCð Cð C�õ % SÑ)Ô)Ð)ÝŒJ�uÑÔÐÝÔÑ Ô Ð ð	!øõ ”^Ñ%Ô%ˆ
Ø Ñ'ˆð	!Ý”NÑ$Ô$ˆEØ˜	Ò!Ð!ØÝŒ~ÑÔ (Ò*Ð*Ý”^Ñ%Ô%¨
Ñ2�ðC¸5À9Ñ;Lð Cð CØ(*Ð9ðCð Cà"'ðCð Cà6?ðCð Cð C�õ % SÑ)Ô)Ð)ÝŒJ�uÑÔÐÝÔÑ Ô Ð ð	!ð 	!ð 	!ð 	!ð 	!s   ¥C ÃB,F c                 ó    — |€t           j        }|                      |¦  «         |                      ¦   «         rd|d›d�}t	          |¦  «        ‚dS )zcJoin a thread. Raise an AssertionError if the thread is still alive
    after timeout seconds.
    Nzfailed to join the thread in r,   z seconds)r   r-   ÚjoinÚis_aliver/   )r    r0   r5   s      r   Újoin_threadr:   j   s`   € ð €ÝÔ'ˆØ
‡K‚K�ÑÔÐØ‡‚ÑÔð "ØC¨gÐCÐCÐCÐCˆÝ˜SÑ!Ô!Ð!ð"ð "r   c              #   ób  K  — dd l }t          | ¦  «        } g }	 	 | D ]+}|                     ¦   «          |                     |¦  «         Œ,n@#  t          j        r.t          dt          | ¦  «        t          |¦  «        fz  ¦  «         ‚ xY wd V — 	 |r
 |¦   «          t          j	        ¦   «         }t          dd¦  «        D ]€}|dz  }|D ]9}|                     t          |t          j	        ¦   «         z
  d¦  «        ¦  «         Œ:d„ |D ¦   «         }|s n.t          j        r!t          dt          |¦  «        |fz  ¦  «         Œ�d	„ |D ¦   «         }|r>|                     t          j        ¦  «         t!          d
t          |¦  «        z  ¦  «        ‚d S # d	„ |D ¦   «         }|r>|                     t          j        ¦  «         t!          d
t          |¦  «        z  ¦  «        ‚w xY w# 	 |r
 |¦   «          t          j	        ¦   «         }t          dd¦  «        D ]€}|dz  }|D ]9}|                     t          |t          j	        ¦   «         z
  d¦  «        ¦  «         Œ:d„ |D ¦   «         }|s n.t          j        r!t          dt          |¦  «        |fz  ¦  «         Œ�d	„ |D ¦   «         }|r>|                     t          j        ¦  «         t!          d
t          |¦  «        z  ¦  «        ‚nQ# d	„ |D ¦   «         }|r>|                     t          j        ¦  «         t!          d
t          |¦  «        z  ¦  «        ‚w xY ww xY w)Nr   z/Can't start %d threads, only %d threads startedr   é   é<   r   c                 ó:   — g | ]}|                      ¦   «         ¯|‘ŒS r   ©r9   ©Ú.0Úts     r   ú
<listcomp>z!start_threads.<locals>.<listcomp>�   s%   € Ð>Ð>Ð> °·²±´Ð>˜1Ð>Ð>Ð>r   z7Unable to join %d threads during a period of %d minutesc                 ó:   — g | ]}|                      ¦   «         ¯|‘ŒS r   r?   r@   s     r   rC   z!start_threads.<locals>.<listcomp>–   s%   € Ð:Ð:Ð:˜Q¨Q¯ZªZ©\¬\Ð:�qÐ:Ð:Ð:r   zUnable to join %d threads)ÚfaulthandlerÚlistÚstartÚappendr   ÚverboseÚprintr   r   r.   r   r8   ÚmaxÚdump_tracebackÚsysÚstdoutr/   )ÚthreadsÚunlockrE   ÚstartedrB   Úendtimer0   s          r   Ústart_threadsrS   v   sß  è è € àÐÐÐÝ�7‰mŒm€GØ€GðQð	Øð "ð "�Ø—’‘	”	�	Ø—’˜qÑ!Ô!Ð!Ð!ð"øð	ÝŒð 4ÝÐGÝ˜7‘|”|¥S¨¡\¤\Ð2ñ3ñ 4ô 4ð 4àøøøØˆˆˆð	QØð Ø�‘”�Ý”nÑ&Ô&ˆGÝ   B™<œ<ð 	Bð 	B�Ø˜2‘�Ø ð Bð B�AØ—F’F�3˜w­¬Ñ)9Ô)9Ñ9¸4Ñ@Ô@ÑAÔAÐAÐAØ>Ð> gÐ>Ñ>Ô>�Øð Ø�EÝ”?ð BÝð 'Ý*-¨g©,¬,¸Ð)@ñAñ Bô Bð Bøð ;Ð: 'Ð:Ñ:Ô:ˆGØð QØ×+Ò+­C¬JÑ7Ô7Ð7Ý$Ð%@Å3ÀwÁ<Ä<Ñ%OÑPÔPÐPðQð Qøð ;Ð: 'Ð:Ñ:Ô:ˆGØð QØ×+Ò+­C¬JÑ7Ô7Ð7Ý$Ð%@Å3ÀwÁ<Ä<Ñ%OÑPÔPÐPÐPÐPÐPÐPøð%	QØð Ø�‘”�Ý”nÑ&Ô&ˆGÝ   B™<œ<ð 	Bð 	B�Ø˜2‘�Ø ð Bð B�AØ—F’F�3˜w­¬Ñ)9Ô)9Ñ9¸4Ñ@Ô@ÑAÔAÐAÐAØ>Ð> gÐ>Ñ>Ô>�Øð Ø�EÝ”?ð BÝð 'Ý*-¨g©,¬,¸Ð)@ñAñ Bô Bð Bøð ;Ð: 'Ð:Ñ:Ô:ˆGØð QØ×+Ò+­C¬JÑ7Ô7Ð7Ý$Ð%@Å3ÀwÁ<Ä<Ñ%OÑPÔPÐPðQøð ;Ð: 'Ð:Ñ:Ô:ˆGØð QØ×+Ò+­C¬JÑ7Ô7Ð7Ý$Ð%@Å3ÀwÁ<Ä<Ñ%OÑPÔPÐPÐPÐPÐPÐPÐPÐPÐPÐPsF   š.A	 ÁG Á	=BÂG ÂB0F ÆAGÇL.ÇB0KÊAL.ËAL*Ì*L.c                   ó*   — e Zd ZdZd„ Zd„ Zd„ Zd„ ZdS )Úcatch_threading_exceptiona  
    Context manager catching threading.Thread exception using
    threading.excepthook.

    Attributes set when an exception is caught:

    * exc_type
    * exc_value
    * exc_traceback
    * thread

    See threading.excepthook() documentation for these attributes.

    These attributes are deleted at the context manager exit.

    Usage:

        with threading_helper.catch_threading_exception() as cm:
            # code spawning a thread which raises an exception
            ...

            # check the thread exception, use cm attributes:
            # exc_type, exc_value, exc_traceback, thread
            ...

        # exc_type, exc_value, exc_traceback, thread attributes of cm no longer
        # exists at this point
        # (to avoid reference cycles)
    c                 óL   — d | _         d | _        d | _        d | _        d | _        d S r   )Úexc_typeÚ	exc_valueÚexc_tracebackr    Ú	_old_hook©Úselfs    r   Ú__init__z"catch_threading_exception.__init__»   s*   € ØˆŒØˆŒØ!ˆÔØˆŒØˆŒˆˆr   c                 óf   — |j         | _         |j        | _        |j        | _        |j        | _        d S r   )rW   rX   rY   r    )r\   r$   s     r   Ú_hookzcatch_threading_exception._hookÂ   s,   € ØœˆŒØœˆŒØ!Ô/ˆÔØ”kˆŒˆˆr   c                 óJ   — t           j        | _        | j        t           _        | S r   )r   Ú
excepthookrZ   r_   r[   s    r   Ú	__enter__z#catch_threading_exception.__enter__È   s   € Ý"Ô-ˆŒØ#œz�	ÔØˆr   c                 ó8   — | j         t          _        | `| `| `| `d S r   )rZ   r   ra   rW   rX   rY   r    )r\   Úexc_infos     r   Ú__exit__z"catch_threading_exception.__exit__Í   s%   € Ø#œ~�	ÔØˆMØˆNØÐØˆKˆKˆKr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r]   r_   rb   re   r   r   r   rU   rU   œ   sZ   € € € € € ðð ð<ð ð ð"ð "ð "ðð ð ð
ð ð ð ð r   rU   Úreturnc                  ól   — t           j        dk    rt           j        j        S t           j        dk    rdS dS )ay  Detect whether Python can start new threads.

    Some WebAssembly platforms do not provide a working pthread
    implementation. Thread support is stubbed and any attempt
    to create a new thread fails.

    - wasm32-wasi does not have threading.
    - wasm32-emscripten can be compiled with or without pthread
      support (-s USE_PTHREADS / __EMSCRIPTEN_PTHREADS__).
    Ú
emscriptenÚwasiFT)rM   ÚplatformÚ_emscripten_infoÚpthreadsr   r   r   Ú_can_start_threadrq   Õ   s6   € õ „|�|Ò#Ð#ÝÔ#Ô,Ð,Ý	Œ˜Ò	Ð	Øˆuð ˆtr   F)Úmodulec                 óx   — d}| rt           st          j        |¦  «        ‚dS t          j        t           |¦  «        S )z†Skip tests or modules that require working threading.

    Can be used as a function/class decorator or to skip an entire module.
    zrequires threading supportN)Úcan_start_threadÚunittestÚSkipTestÚ
skipUnless)rr   r5   s     r   Úrequires_working_threadingrx   ê   sJ   € ð
 '€CØð :Ýð 	)ÝÔ# CÑ(Ô(Ð(ð	)ð 	)õ Ô"Õ#3°SÑ9Ô9Ð9r   r   )r   Ú
contextlibr(   rM   r   r   ru   Útestr   r   r!   r*   Úcontextmanagerr6   r:   rS   rU   Úboolrq   rt   rx   r   r   r   ú<module>r}      si  ðØ €€€Ø Ð Ð Ð Ø Ð Ð Ð Ø 
€
€
€
Ø Ð Ð Ð Ø €€€Ø €€€à Ð Ð Ð Ð Ð ð8ð 8ð 8ðð ð ð6ð ð ð Ôð!!ð !!ð !!ñ Ôð!!ðH	"ð 	"ð 	"ð 	"ð Ôð"Qð "Qð "Qñ Ôð"QðJ6ð 6ð 6ð 6ð 6ñ 6ô 6ð 6ðr˜4ð ð ð ð ð& %Ð$Ñ&Ô&Ð à).ð 
:ð 
:ð 
:ð 
:ð 
:ð 
:ð 
:r   