File: //usr/local/lib/python3.10/test/support/__pycache__/threading_helper.cpython-310.opt-1.pyc
o
�i� � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ dd� Zdd� Z dd� Z
ejdd d
��Zddd�Z
ejdd
d��ZG dd� d�ZdS )� N)�supportc C s t �� tj�� fS �N)�_thread�_count� threading� _dangling�copy� r r �:/usr/local/lib/python3.10/test/support/threading_helper.py�threading_setup s r c
G s� d}t |�D ]L}t�� tjf}|| kr d S |sGdt_|d }t�d|d | d � d|d � dt|�� d�� |D ]
}t�d |��� q:d }d }t �
d
� t�� qd S )N�d T� z&threading_cleanup() failed to cleanup r z threads (count: z, dangling: �)zDangling thread: �{�G�z�?)�ranger r r r r Zenvironment_alteredZ
print_warning�len�time�sleep�
gc_collect)Zoriginal_valuesZ
_MAX_COUNT�count�valuesZdangling_threads�threadr r r
�threading_cleanup s, ��
�
�r c s t �� �� fdd��}|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 s$ t � }z � | � W t|� S t|� w r )r r )�args�key��funcr r
� decorator: s zreap_threads.<locals>.decorator)� functools�wraps)r r r r r
�reap_threads6 s r c c s � | du rt j} t�� }zCdV W t�� }|| } t�� }||kr$dS t�� |krFt�� | }d|| � d|d�d|� d|� d� }t|��t�d � t �� qt�� }|| } t�� }||krc w t�� |kr�t�� | }d|| � d|d�d|� d|� d� }t|��t�d � t �� qY)
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 )�timeoutZ old_countZ
start_time�deadliner Zdt�msgr r r
�wait_threads_exitD sZ ����
������
�r( c C s: |du rt j}| �|� | �� rd|d�d�}t|��dS )zcJoin a thread. Raise an AssertionError if the thread is still alive
after timeout seconds.
Nzfailed to join the thread in r! z seconds)r r"