CasperSecurity

Current Path : /usr/lib/python3.10/test/support/__pycache__/
Upload File :
Current File : //usr/lib/python3.10/test/support/__pycache__/threading_helper.cpython-310.pyc

o

`�wi��@s�ddlZddlZddlZddlZddlZddlZddlmZdd�Zdd�Z	dd�Z
ejdd	d
��Zddd�Z
ejdd
d��ZGdd�d�ZdS)�N)�supportcCst��tj��fS�N)�_thread�_count�	threading�	_dangling�copy�r	r	�4/usr/lib/python3.10/test/support/threading_helper.py�threading_setupsrc
Gs�d}t|�D]L}t��tjf}||krdS|sGdt_|d}t�d|d|d�d|d�dt|��d��|D]
}t�d	|���q:d}d}t	�
d
�t��qdS)N�dT�z&threading_cleanup() failed to cleanup rz threads (count: z, dangling: �)zDangling thread: �{�G�z�?)�rangerrrrr�environment_altered�
print_warning�len�time�sleep�
gc_collect)�original_values�
_MAX_COUNT�count�values�dangling_threads�threadr	r	r
�threading_cleanups,��
�

�rcst����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.
    cs$t�}z	�|�Wt|�St|�wr)rr)�args�key��funcr	r
�	decorator:szreap_threads.<locals>.decorator)�	functools�wraps)r!r"r	r r
�reap_threads6sr%ccs�|durtj}t��}zCdVWt��}||}	t��}||kr$dSt��|krFt��|}d||�d|d�d|�d|�d�	}t|��t�d	�t��qt��}||}	t��}||krc	wt��|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: rr)	r�
SHORT_TIMEOUTrrr�	monotonic�AssertionErrorrr)�timeout�	old_count�
start_time�deadliner�dt�msgr	r	r
�wait_threads_exitDsZ����
������
�r0cCs:|durtj}|�|�|��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)rr'�join�is_aliver))rr*r/r	r	r
�join_threadis
�r3ccs,�ddl}t|�}g}z�z|D]}|��|�|�qWntjr/tdt|�t|�f��dVWzX|r:|�t�	�}t
dd�D]/}|d7}|D]}|�t|t�	�d��qKdd�|D�}|sentjrrtd	t|�|f�qCWd
d�|D�}|r�|�
tj�tdt|���dSd
d�|D�}|r�|�
tj�tdt|���wzW|r�|�t�	�}t
dd�D]/}|d7}|D]}|�t|t�	�d��q�dd�|D�}|s�ntjr�td	t|�|f�q�Wd
d�|D�}|r�|�
tj�tdt|���wd
d�|D�}|�r|�
tj�tdt|���w)Nrz/Can't start %d threads, only %d threads startedr
��<rcS�g|]}|��r|�qSr	�r2��.0�tr	r	r
�
<listcomp>��z!start_threads.<locals>.<listcomp>z7Unable to join %d threads during a period of %d minutescSr6r	r7r8r	r	r
r;�r<zUnable to join %d threads)�faulthandler�list�start�appendr�verbose�printrrr(rr1�max�dump_traceback�sys�stdoutr))�threads�unlockr=�startedr:�endtimer*r	r	r
�
start_threadsus����
�����
���rKc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
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)
    cCs"d|_d|_d|_d|_d|_dSr)�exc_type�	exc_value�
exc_tracebackr�	_old_hook��selfr	r	r
�__init__�s

z"catch_threading_exception.__init__cCs$|j|_|j|_|j|_|j|_dSr)rMrNrOr)rRrr	r	r
�_hook�szcatch_threading_exception._hookcCstj|_|jt_|Sr)r�
excepthookrPrTrQr	r	r
�	__enter__�sz#catch_threading_exception.__enter__cGs|jt_|`|`|`|`dSr)rPrrUrMrNrOr)rR�exc_infor	r	r
�__exit__�s
z"catch_threading_exception.__exit__N)�__name__�
__module__�__qualname__�__doc__rSrTrVrXr	r	r	r
rL�srLr)r�
contextlibr#rErr�testrrrr%�contextmanagerr0r3rKrLr	r	r	r
�<module>s 
$%
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY