Sindbad~EG File Manager

Current Path : /proc/2568807/root/usr/local/lib/python3.12/test/__pycache__/
Upload File :
Current File : //proc/2568807/root/usr/local/lib/python3.12/test/__pycache__/test_threading.cpython-312.opt-2.pyc

�

'Μg$����	ddlZddlmZmZddlmZmZmZddlmZddl	m
Z
mZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZddlmZ	dd	lmZej<d
��dZd
�Z d�Z!d�Z"Gd�de#�Z$Gd�dejJ�Z&Gd�dejN�Z(Gd�de(�Z)Gd�de(�Z*Gd�de(�Z+Gd�de(�Z,Gd�dejJ�Z-Gd �d!e(�Z.Gd"�d#e(�Z/Gd$�d%ej`�Z0Gd&�d'ejb�Z2ejfejhdud(�Gd)�d*ejb��Z5Gd+�d,ejl�Z6Gd-�d.ejb�Z7Gd/�d0ejp�Z8Gd1�d2ejr�Z9Gd3�d4ejt�Z:Gd5�d6ejv�Z;Gd7�d8ejN�Z<Gd9�d:ejN�Z=Gd;�d<ejN�Z>e?d=k(rej��yy#e$rdZY���wxYw)>�N)�threading_helper�requires_subprocess)�verbose�cpython_only�	os_helper)�
import_module)�assert_python_ok�assert_python_failure)�mock)�
lock_tests)�support)�interpretersT)�module)�netbsd5zhp-ux11c�j�tjstjd�|�Stj
tvrtjd�|�Stjrtjd�|�Stjd��rtjd�S|S)Nzrequires working os.fork()z*due to known OS bug related to thread+forkz?libasan has a pthread_create() dead lock related to thread+forkT��threadz'TSAN doesn't support threads after fork)	r
�has_fork_support�unittest�skip�sys�platform�platforms_to_skip�HAVE_ASAN_FORK_BUG�check_sanitizer)�tests �0/usr/local/lib/python3.12/test/test_threading.py�skip_unless_reliable_forkr+s����#�#�:�x�}�}�9�:�4�@�@�
�|�|�(�(�J�x�}�}�I�J�4�P�P��!�!�_�x�}�}�^�_�`d�e�e����d�+��}�}�F�G�G��K�c�H�	tjtdud�|�S)Nzsubinterpreters required)r�skipIfr)�meths r�requires_subinterpretersr#7s,��H�7�8�?�?�<�4�/�5�7�7;�=�=rc��|jttdtj�tjt_y)N�
excepthook)�
addCleanup�setattr�	threadingr%�__excepthook__)�testcases r�restore_default_excepthookr+=s*�������L�)�:N�:N�O�$�3�3�I�rc�$�eZdZd�Zd�Zd�Zd�Zy)�Counterc��d|_y)Nr��value��selfs r�__init__zCounter.__init__Ds	����
rc�.�|xjdz
c_y�N�r/r1s r�inczCounter.incF����
�
�a��
rc�.�|xjdzc_yr5r/r1s r�deczCounter.decHr8rc��|jS�Nr/r1s r�getzCounter.getJs���z�z�rN)�__name__�
__module__�__qualname__r3r7r:r=�rrr-r-Cs�����rr-c��eZdZd�Zd�Zy)�
TestThreadc�~�tjj||��||_||_||_||_y)N��name)r(�Threadr3r*�sema�mutex�nrunning)r2rFr*rHrIrJs      rr3zTestThread.__init__Ns7�����!�!�$�T�!�2� ��
���	���
� ��
rc��tj�dz}trtd|j|dzfz�|j5|j
5|jj�tr$t|jj�d�|jj|jj�d�ddd�tj|�trtd|jd�|j
5|jj�|jj|jj�d�tr2td	|j|jj�fz�ddd�ddd�y#1swY��xYw#1swY�xYw#1swYyxYw)
Ng��@ztask %s will run for %.1f usecg��.Aztasks are running��task�donerz$%s is finished. %d tasks are running)�randomr�printrFrHrIrJr7r=r*�assertLessEqual�time�sleepr:�assertGreaterEqual)r2�delays  r�runzTestThread.runUs=���
�
��'�)����2��9�9�e�c�k�*�+�
,��Y�Y�����
�
�!�!�#���$�-�-�+�+�-�/B�C��
�
�-�-�d�m�m�.?�.?�.A�1�E�	�
�J�J�u����f�d�i�i��0�����
�
�!�!�#��
�
�0�0����1B�1B�1D�a�H���@��9�9�d�m�m�&7�&7�&9�:�;�<�	��Y��������Y�s?�
G�A9F+�
AG�BF7�G�+F4	�0G�7G	�<G�GN)r>r?r@r3rVrArrrCrCMs��!�<rrCc��eZdZd�Zd�Zy)�BaseTestCasec�6�tj�|_yr<)r�threading_setup�_threadsr1s r�setUpzBaseTestCase.setUpos��(�8�8�:��
rc�x�tj|j�tjj�yr<)r�threading_cleanupr[rr
�
reap_childrenr1s r�tearDownzBaseTestCase.tearDownrs$���*�*�D�M�M�:����"�"�$rN)r>r?r@r\r`rArrrXrXns��;�%rrXc�t�eZdZdZed��Zd�Zed��Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zed��Zed��Zd�Zeej8eed�d�d���Zeej8eed�d�d���Z ejBe"jFe$vd�e%jL�ej8eed�d�d/d����Z'd/d�Z(d�Z)d�Z*d �Z+d!�Z,d"�Z-ed#��Z.d$�Z/d%�Z0d&�Z1d'�Z2ed(��Z3d)�Z4d*�Z5d+�Z6d,�Z7d-�Z8y.)0�ThreadTestsi'c���d�}tjd��}|j|jd�tjd��}|j|jd�tj|d��}|j|jd�tj
j
tdd	�
�5tjd��}|j|jd�ddd�tj
j
tdd
�
�5tj�}|j|jd�ddd�tj
j
tdd�
�5tj|��}|j|jd�ddd�y#1swY��xYw#1swY�wxYw#1swYyxYw)Nc��yr<rArArr�funcz#ThreadTests.test_name.<locals>.func|���Dr�myname1rE�{�123�myname2)�targetrF�_counter�)�return_value�zThread-2rLzThread-3��rkzThread-5 (func))r(rG�assertEqualrFr�patch�object)r2rers   r�	test_namezThreadTests.test_namezsd����!�!�y�1��������i�0��!�!�s�+��������e�,��!�!��I�>��������i�0�
�Z�Z�
�
�y�*�1�
�
E��%�%�2�.�F����V�[�[�*�5�F��Z�Z�
�
�y�*�1�
�
E��%�%�'�F����V�[�[�*�5�F��Z�Z�
�
�y�*�1�
�
E��%�%�T�2�F����V�[�[�*;�<�F�
E�F�
E��F�
E��F�
E�s$�3F=�"1G	�3G�=G�	G�Gc�F��dg}d}dg}d}dgf}dg}|�fd�f|�fd�f|�fd�f|�fd�f|�fd	�f|�fd
�ff}|D]X\}}	�j|	|��5tj|	|��}
|
j�|
j	�ddd��Zy#1swY�exYw)Nr6�r6�str�rxc�(���j|d�Sr5�rr��argr2s �r�<lambda>z0ThreadTests.test_args_argument.<locals>.<lambda>�s���4�#3�#3�C��#;rc�(���j|d�Sr5r{r|s �rr~z0ThreadTests.test_args_argument.<locals>.<lambda>�s���D�$4�$4�S�!�$<rc�(���j|d�S�Nrxr{r|s �rr~z0ThreadTests.test_args_argument.<locals>.<lambda>�s���4�#3�#3�C��#?rc�(���j|d�Sr�r{r|s �rr~z0ThreadTests.test_args_argument.<locals>.<lambda>�s���D�$4�$4�S�%�$@rc�*���j|dg�Sr5r{r|s �rr~z0ThreadTests.test_args_argument.<locals>.<lambda>�s����(8�(8��q�c�(Brc�(���j|d�S)Nrwr{r|s �rr~z0ThreadTests.test_args_argument.<locals>.<lambda>�s����(8�(8��d�(Cr�rk�args)�subTestr(rG�start�join)r2�num_list�	num_tuple�str_list�	str_tuple�
list_in_tuple�
tuple_in_list�
test_casesr�rk�ts`          r�test_args_argumentzThreadTests.test_args_argument�s�����3���	��7���	����
���
��;�<�
�<�=�
�?�@�
�@�A�
�B�C�
�C�D�

�
�'�L�D�&����V�$��7��$�$�F��>�����	�����8�7�'�7�7�s�8B�B 	c�~�tj�}tjj	|t|��yr<)r(�Lockrr
�check_disallow_instantiation�type�r2�locks  r�test_disallow_instantiationz'ThreadTests.test_disallow_instantiation�s(���~�~������1�1�$��T�
�Crc���d}tjd��}tj�}t�}g}t	|�D]k}td|z||||�}|j
|�|j|j�|jt|�d�|j��mttd�rXtd�|D��tj�hz}|jd|�|j!t#|�|dz�t$rt'd	�|D]�}|j)�|j+|j-��|j/|jd
�|j1|j�|jt|�d���t$rt'd�|j!|j3�d
�y)
N�
rLr/z<thread %d>z^<TestThread\(.*, initial\)>$�
get_native_idc3�4K�|]}|j���y�wr<)�	native_id)�.0r�s  r�	<genexpr>z/ThreadTests.test_various_ops.<locals>.<genexpr>�s����:�'�Q�Q�[�[�'�s�r6z!waiting for all tasks to completerz#^<TestThread\(.*, stopped -?\d+\)>$zall tasks done)r(�BoundedSemaphore�RLockr-�rangerC�append�assertIsNone�ident�assertRegex�reprr��hasattr�setr��assertNotInrr�lenrrPr��assertFalse�is_alive�assertNotEqual�assertIsNotNoner=)	r2�NUMTASKSrHrI�
numrunning�threads�ir��
native_idss	         r�test_various_opszThreadTests.test_various_ops�s{�����)�)��2�����!���Y�
����x��A��=��?�D�$��z�J�A��N�N�1�����a�g�g�&����T�!�W�&F�G�
�G�G�I�!��9�o�.��:�'�:�:�i�>U�>U�>W�=X�X�J����T�:�.����S��_�h��l�;���5�6��A�
�F�F�H����Q�Z�Z�\�*��������+�� � ����)����T�!�W�&L�M����"�#�������)�1�-rc����|jtj�j���fd�}tj��g�tj�5tj|d�}�j�|j�d|�ddd�tj�d=y#1swY�xYw)Nc����jtj�j��j	�yr<)r�r(�current_threadr�r�)rNr�s��r�fz9ThreadTests.test_ident_of_no_threading_threads.<locals>.f�s'����L�L��1�1�3�9�9�:��H�H�JrrAr)r�r(r�r��Eventr�wait_threads_exit�_thread�start_new_thread�waitrr�_active)r2r��tidrNr�s   @@r�"test_ident_of_no_threading_threadsz.ThreadTests.test_ident_of_no_threading_threads�s�������Y�5�5�7�=�=�>�	���� ����
�
/�
/�
1��*�*�1�b�1�C��I�I�K����U�1�X�s�+�2�

���e�A�h�'�2�
1�s� <B9�9Cc���trtd�	tjd�|j�tjd�y#tj
$rt
jd��wxYw)Nz!with 256 KiB thread stack size...i�4platform does not support changing thread stack sizer�	rrPr(�
stack_sizer��errorr�SkipTestr�r1s r�test_various_ops_small_stackz(ThreadTests.test_various_ops_small_stack�sm����5�6�	H�� � ��(�	
�������Q���	�}�}�	H��#�#�F�H�
H�	H���A�)A7c���trtd�	tjd�|j�tjd�y#tj
$rt
jd��wxYw)Nzwith 1 MiB thread stack size...ir�rr�r1s r�test_various_ops_large_stackz(ThreadTests.test_various_ops_large_stack�sm����3�4�	H�� � ��*�	
�������Q���	�}�}�	H��#�#�F�H�
H�	H�r�c�n�d�}tj�}|j�tj�5tj||f�}|j�ddd�|jtj�|jtj|tj�|jtj|j��|jttj|�d�tj|=y#1swY��xYw)Nc�L�tj�|j�yr<)r(r��release)rIs rr�z*ThreadTests.test_foreign_thread.<locals>.fs��
�$�$�&��M�M�Or�_DummyThread)r(r��acquirerr�r�r��assertInr��assertIsInstancer��
assertTruer�r�r�)r2r�rIr�s    r�test_foreign_threadzThreadTests.test_foreign_threads���	���� ��
�
�
��
�
/�
/�
1��*�*�1�u�h�7�C��M�M�O�2�	
�
�
�c�9�,�,�-����i�/�/��4�i�6L�6L�M����	�)�)�#�.�7�7�9�:�����i�/�/��4�5�~�F����c�"�2�
1�s�(D+�+D4c��	�
��td�}|jj}|j|jf|_Gd�dt��	|j	�	�}tj�}|j|t�|j|d�	|||�}		�#�	$rYnwxYw	|jd�n#t$rYnwxYwtj��tj��
G�	�
�fd�dtj �}|�}d|_|j%�t&rt)d	�t&rt)d
�|d|�}|j|d�t&rt)d��j+�}|j-|�t&rt)d
�|j/|j0�t&rt)d�||j2|�}|j|d�t&rt)d��
j+t4j6��|j-|j0�t&rt)d�|j0r|j9�yy)N�ctypesc��eZdZy)�<ThreadTests.test_PyThreadState_SetAsyncExc.<locals>.AsyncExcN)r>r?r@rArr�AsyncExcr� s��rr�rTr6c���eZdZ���fd�Zy)�:ThreadTests.test_PyThreadState_SetAsyncExc.<locals>.Workerc����tj�|_d|_		�j	�tjd��&#�$rd|_�j	�YywxYw)NFTg�������?)r(�	get_ident�id�finishedr�rRrS)r2r��worker_saw_exception�worker_starteds ���rrVz>ThreadTests.test_PyThreadState_SetAsyncExc.<locals>.Worker.runDsb���#�-�-�/��� %��
�/��&�*�*�,��
�
�3���� �/�$(�D�M�(�,�,�.�/�s�'A
�
A)�(A)N�r>r?r@rV)r�r�r�s���r�Workerr�Cs���

/rr�z    started worker threadz     trying nonsensical thread id���z,    waiting for worker thread to get startedz"    verifying worker hasn't exitedz2    attempting to raise asynch exception in workerz5    waiting for worker to say it caught the exception��timeoutz    all OK -- joining worker)r�	pythonapi�PyThreadState_SetAsyncExc�c_ulong�	py_object�argtypes�	Exceptionr(r�r��int�
assertGreater�failrr�UnboundLocalErrorr�rG�daemonr�rrPr�r�r�r�r�r
�
SHORT_TIMEOUTr�)r2r��
set_async_exc�	exceptionr��resultr�r��retr�r�r�s         @@@r�test_PyThreadState_SetAsyncExcz*ThreadTests.test_PyThreadState_SetAsyncExcs!����x�(���(�(�B�B�
�"(�.�.�&�2B�2B�!C�
��	�y�	��$�$�X�.�	��!�!�#�����c�3�'����3��"�	-�"�3�	�2�F������	��	��	����V�Q�'�� �	��	��#���*��(���0��	/�	/�Y�%�%�	/�
�H�����	���	���-�.���4�5��r�9�-�������#���@�A��!�!�#���������6�7�������$���F�G��q�t�t�Y�/�������#���I�J��!�!�'�*?�*?�!�@�����
�
�#���0�1��:�:�
�F�F�H�s$�B+�+B3�2B3�7C
�
	C�Cc�>�d�}tj}|t_	tjd���}|jtj|j
�|j
|tjvd�|t_y#|t_wxYw)Nc�*�tj��r<)r(�ThreadError�r�s r�fail_new_threadz7ThreadTests.test_limbo_cleanup.<locals>.fail_new_threadts���'�'�)�)rc��yr<rArArrr~z0ThreadTests.test_limbo_cleanup.<locals>.<lambda>y���rrqz:Failed to cleanup _limbo map on failure of Thread.start().)r(�_start_new_threadrG�assertRaisesr�r�r��_limbo)r2r�rr�s    r�test_limbo_cleanupzThreadTests.test_limbo_cleanuprs~��	*�%�7�7��&5�	�#�	<�� � ��5�A����i�3�3�Q�W�W�=�����Y�%�%�%�L�
N�+<�I�'��*;�I�'�s�A#B�
Bc��tjd��r|jd�td�t	dd�\}}}|j|d�y)NTr�TSAN would report thread leakr��-caNif 1:
            import ctypes, sys, time, _thread

            # This lock is used as a simple event variable.
            ready = _thread.allocate_lock()
            ready.acquire()

            # Module globals are cleared before __del__ is run
            # So we save the functions in class dict
            class C:
                ensure = ctypes.pythonapi.PyGILState_Ensure
                release = ctypes.pythonapi.PyGILState_Release
                def __del__(self):
                    state = self.ensure()
                    self.release(state)

            def waitingThread():
                x = C()
                ready.release()
                time.sleep(100)

            _thread.start_new_thread(waitingThread, ())
            ready.acquire()  # Be sure the other thread is waiting.
            sys.exit(42)
            �*)r
r�skipTestrr
rr�r2�rc�out�errs    r�test_finalize_running_threadz(ThreadTests.test_finalize_running_thread�sR���"�"�$�/�
�M�M�9�:��h��,�T�4����C��2	
����R� rc�j�tjd��r|jd�tdd�y)NTrrraPif 1:
            import sys, threading

            # A deadlock-killer, to prevent the
            # testsuite to hang forever
            def killer():
                import os, time
                time.sleep(2)
                print('program blocked; aborting')
                os._exit(2)
            t = threading.Thread(target=killer)
            t.daemon = True
            t.start()

            # This is the trace function
            def func(frame, event, arg):
                threading.current_thread()
                return func

            sys.settrace(func)
            )r
rrr	r1s r�test_finalize_with_tracez$ThreadTests.test_finalize_with_trace�s0���"�"�$�/�
�M�M�9�:��� �	rc��tdd�\}}}|j|j�d�|j|d�y)Nra�if 1:
                import threading
                from time import sleep

                def child():
                    sleep(1)
                    # As a non-daemon thread we SHOULD wake up and nothing
                    # should be torn down yet
                    print("Woke up, sleep function is:", sleep)

                threading.Thread(target=child).start()
                raise SystemExit
            s5Woke up, sleep function is: <built-in function sleep>r�r	rr�stripr	s    r�test_join_nondaemon_on_shutdownz+ThreadTests.test_join_nondaemon_on_shutdown�sG��(��/����C��	
�������D�	F�����c�"rc��tj}tj�}	t	dd�D]p}tj
|dz�tjd���}|j�|j�|�}|j||d||fz��r	tj
|�y#tj
|�wxYw)Nr6�dg-C��6*?c��yr<rArArrr~z7ThreadTests.test_enumerate_after_join.<locals>.<lambda>�s��Drrqz&#1703448 triggered after %d trials: %s)
r(�	enumerater�getswitchintervalr��setswitchintervalrGr�r�r�)r2�enum�old_intervalr�r��ls      r�test_enumerate_after_joinz%ThreadTests.test_enumerate_after_join�s����"�"���,�,�.��
	0��1�c�]���%�%�a�&�j�1��$�$�L�9�����	������F��� � ��A�<��1�v�E�G�
#�
�!�!�,�/��C�!�!�,�/�s�A?B<�<Cc���Gd�dt�}t|�|d��}tj|�}|jj�~|j
|�dtj|��z��|d��}tj|�}|jj�~|j
|�dtj|��z��y)Nc��eZdZd�Zd�Zy)�DThreadTests.test_no_refcycle_through_target.<locals>.RunSelfFunctionc��||_tj|j|fd|i��|_|jj�y)N�yet_another)rkr��kwargs)�should_raiser(rG�_runrr�)r2r$s  rr3zMThreadTests.test_no_refcycle_through_target.<locals>.RunSelfFunction.__init__�sD��%1��!�'�.�.�d�i�i�59�G�7D�T�6J�L������!�!�#rc�(�|jrt�yr<)r$�
SystemExit)r2�	other_refr"s   rr%zIThreadTests.test_no_refcycle_through_target.<locals>.RunSelfFunction._run�s���$�$�$�$�%rN)r>r?r@r3r%rArr�RunSelfFunctionr �s��
$�
%rr)F)r$z%d references still around)�msgT)	rtr+�weakref�refrr�r�r�getrefcount)r2r)�
cyclic_object�weak_cyclic_object�raising_cyclic_object�weak_raising_cyclic_objects      r�test_no_refcycle_through_targetz+ThreadTests.test_no_refcycle_through_target�s���	%�f�	%�	#�4�(�'�U�;�
�$�[�[��7�����!�!�#�����,�.�:�!�o�o�.@�.B�C�D�	�	F�!0�T� B��%,�[�[�1F�%G�"��$�$�)�)�+�!����4�6�:�!�o�o�.H�.J�K�L�	�	Nrc�h�tj�}|jtd�5|j	�ddd�|jtd�5|jd�ddd�|jtd�5|j
�ddd�|jtd�5|jd�ddd�tj�}|jtd�5|j�ddd�tj�}|j�|jtd�5|j�ddd�|jtd	�5tj�ddd�|jtd
�5tj�ddd�y#1swY���xYw#1swY��sxYw#1swY��QxYw#1swY��.xYw#1swY��xYw#1swY��xYw#1swY��xYw#1swYyxYw)Nzget the daemon attributezset the daemon attributeTzget the name attributezset the name attributerFzuse is_set()zuse notify_all()zuse active_count()zuse current_thread())r(rG�assertWarnsRegex�DeprecationWarning�isDaemon�	setDaemon�getName�setNamer��isSet�	Conditionr��	notifyAll�activeCount�
currentThread)r2r��e�conds    r�test_old_threading_apiz"ThreadTests.test_old_threading_api
s���
�����
�
"�
"�#5�#>�@�
�J�J�L�@��
"�
"�#5�#>�@�
�K�K���@��
"�
"�#5�#<�>�
�I�I�K�>��
"�
"�#5�#<�>�
�I�I�f��>�
�O�O���
�
"�
"�#5�~�
F�
�G�G�I�G��"�"�$������
�
"�
"�#5�7I�
J��N�N��K��
"�
"�#5�7K�
L��!�!�#�M�
�
"�
"�#5�7M�
N��#�#�%�O�
N�1@�@��@�@��>�>��>�>��
G�
F��
K�
J��M�
L��
N�
N�s_�G�G�
G*�9G7�=H�H�?H�2H(�G�G'�*G4�7H�H
�H�H%�(H1c��tj�}|jdt|��d|_|jdt|��y�Nr�T)r(rGr�r�r�r��r2r�s  r�test_repr_daemonzThreadTests.test_repr_daemon)s=�����������4��7�+�����
�
�h��Q��(rc�&�tj�}|j|j�tjd��}|j|j�tjd��}|j	|j�y)NF�r�T)r(rGr�r�r�rDs  r�test_daemon_paramzThreadTests.test_daemon_param/sd�������������"����E�*��������"����D�)��������!rc�p�d}td|�\}}}|j|d�|j|d�y)Na�if 1:
            import _thread, threading, os, time, warnings

            def background_thread(evt):
                # Creates and registers the _DummyThread instance
                threading.current_thread()
                evt.set()
                time.sleep(10)

            evt = threading.Event()
            _thread.start_new_thread(background_thread, (evt,))
            evt.wait()
            assert threading.active_count() == 2, threading.active_count()
            with warnings.catch_warnings(record=True) as ws:
                warnings.filterwarnings(
                        "always", category=DeprecationWarning)
                if os.fork() == 0:
                    assert threading.active_count() == 1, threading.active_count()
                    os._exit(0)
                else:
                    assert ws[0].category == DeprecationWarning, ws[0]
                    assert 'fork' in str(ws[0].message), ws[0]
                    os.wait()
        rr�r	rr�r2�code�_rrs     r�test_dummy_thread_after_forkz(ThreadTests.test_dummy_thread_after_fork7s=����0'�t�T�2���3������c�"�����c�"rc�H�tj�}|jtj|�tj
jd�t
d�D]�}tjd���}|j�tjtd��5tj�x}dk(r(tj|j!�rdnd	�n'|j#�tj$|d	�
�ddd���y#1swY��xYw)Ng���ư>�c��yr<rArArrr~z6ThreadTests.test_is_alive_after_fork.<locals>.<lambda>br�rrq�ignore��category�actionr�r���exitcode)rrr&rrr
r�r(rGr��warnings�catch_warningsr5�os�fork�_exitr�r��wait_process)r2rr�r��pids     r�test_is_alive_after_forkz$ThreadTests.test_is_alive_after_forkWs����,�,�.������-�-�|�<�	
���&�&�t�,��r��A�� � ��5�A�
�G�G�I��(�(�2D�08�:��7�7�9�$�C��*��H�H�1�:�:�<�R�R�8��F�F�H��(�(��r�:�:�:�	�:�:�s
�$A)D�D!	c���tj�}�j|jd��j|jtj
�j��j|jtj���fd�}tj|��}|j�|j�y)N�
MainThreadc����jtj�jtj�j�yr<)r�r(�main_threadr�r�r1s�rr�z'ThreadTests.test_main_thread.<locals>.fts5������	� 5� 5� 7� =� =� )� 8� 8� :� @� @�
Brrq)
r(rdrrrFr�r�r�rGr�r�)r2�mainr��ths`   r�test_main_threadzThreadTests.test_main_threadns�����$�$�&��������L�1�������Y�%=�%=�%?�%E�%E�F�������Y�%8�%8�%:�;�	B��
�
�Q�
'��
���
�
���	r�waitpidztest needs os.waitpid()c��d}td|�\}}}|j�jdd�}|j|d�|j|d�y)Na!if 1:
            import os, threading
            from test import support

            ident = threading.get_ident()
            pid = os.fork()
            if pid == 0:
                print("current ident", threading.get_ident() == ident)
                main = threading.main_thread()
                print("main", main.name)
                print("main ident", main.ident == ident)
                print("current is main", threading.current_thread() is main)
            else:
                support.wait_process(pid, exitcode=0)
        r�
rorzHcurrent ident True
main MainThread
main ident True
current is main True
�r	�decode�replacerr�r2rLrMrr�datas      r�test_main_thread_after_forkz'ThreadTests.test_main_thread_after_fork{sZ����'�t�T�2���3���z�z�|�#�#�D�"�-������c�"�����2�	3rc���d}td|�\}}}|j�jdd�}|j|jd�d�|j|d�y)Na�if 1:
            import os, threading, sys, warnings
            from test import support

            def func():
                ident = threading.get_ident()
                with warnings.catch_warnings(record=True) as ws:
                    warnings.filterwarnings(
                            "always", category=DeprecationWarning)
                    pid = os.fork()
                    if pid == 0:
                        print("current ident", threading.get_ident() == ident)
                        main = threading.main_thread()
                        print("main", main.name, type(main).__name__)
                        print("main ident", main.ident == ident)
                        print("current is main", threading.current_thread() is main)
                        # stdout is fully buffered because not a tty,
                        # we have to flush before exit.
                        sys.stdout.flush()
                    else:
                        assert ws[0].category == DeprecationWarning, ws[0]
                        assert 'fork' in str(ws[0].message), ws[0]
                        support.wait_process(pid, exitcode=0)

            th = threading.Thread(target=func)
            th.start()
            th.join()
        rrjro�utf-8zTcurrent ident True
main Thread-1 (func) Thread
main ident True
current is main True
rkrns      r�/test_main_thread_after_fork_from_nonmain_threadz;ThreadTests.test_main_thread_after_fork_from_nonmain_thread�sc����8'�t�T�2���3���z�z�|�#�#�D�"�-��������G�,�b�1�����2�	r�due to known OS bugc���d|z}tddd|�\}}}|j�jdd�}|j|j�d�|j||rdndd|�d	�zd
z�y)NaCif 1:
            import os, threading, sys, traceback, _thread
            from test import support

            def func(lock):
                ident = threading.get_ident()
                if %s:
                    # call current_thread() before fork to allocate DummyThread
                    current = threading.current_thread()
                    print("current", current.name, type(current).__name__)
                print("ident in _active", ident in threading._active)
                # flush before fork, so child won't flush it again
                sys.stdout.flush()
                pid = os.fork()
                if pid == 0:
                    print("current ident", threading.get_ident() == ident)
                    main = threading.main_thread()
                    print("main", main.name, type(main).__name__)
                    print("main ident", main.ident == ident)
                    print("current is main", threading.current_thread() is main)
                    print("_dangling", [t.name for t in list(threading._dangling)])
                    # stdout is fully buffered because not a tty,
                    # we have to flush before exit.
                    sys.stdout.flush()
                    try:
                        threading._shutdown()
                        os._exit(0)
                    except:
                        traceback.print_exc()
                        sys.stderr.flush()
                        os._exit(1)
                else:
                    try:
                        support.wait_process(pid, exitcode=0)
                    except Exception:
                        # avoid 'could not acquire lock for
                        # <_io.BufferedWriter name='<stderr>'> at interpreter shutdown,'
                        traceback.print_exc()
                        sys.stderr.flush()
                    finally:
                        lock.release()

            join_lock = _thread.allocate_lock()
            join_lock.acquire()
            th = _thread.start_new_thread(func, (join_lock,))
            join_lock.acquire()
        z-Wzignore::DeprecationWarningrrjrozcurrent Dummy-1 _DummyThread
zident in _active �
zmcurrent ident True
main MainThread _MainThread
main ident True
current is main True
_dangling ['MainThread']
rk)r2�create_dummyrLrMrrros       r�/test_main_thread_after_fork_from_foreign_threadz;ThreadTests.test_main_thread_after_fork_from_foreign_thread�s���.�\�].��b'�t�-I�4�QU�V���3���z�z�|�#�#�D�"�-���������r�*�����>J�:�PR�,�\�,<�B�?�@�6�6�	7rc�(�|jd��y)NT)rw)rx)r2rws  r�-test_main_thread_after_fork_from_dummy_threadz9ThreadTests.test_main_thread_after_fork_from_dummy_threads���<�<�$�<�Orc��d}td|�\}}}|j�}|j|d�|j|j�dgdz�y)Na�if 1:
            import gc, threading

            main_thread = threading.current_thread()
            assert main_thread is threading.main_thread()  # sanity check

            class RefCycle:
                def __init__(self):
                    self.cycle = self

                def __del__(self):
                    print("GC:",
                          threading.current_thread() is main_thread,
                          threading.main_thread() is main_thread,
                          threading.enumerate() == [main_thread])

            RefCycle()
            gc.collect()  # sanity check
            x = RefCycle()
        rrzGC: True True Truerm)r	rlrr�
splitlinesrns      r� test_main_thread_during_shutdownz,ThreadTests.test_main_thread_during_shutdownsZ����('�t�T�2���3���z�z�|������c�"�������*�.�/�!�3�	5rc�L�d}td|�\}}}|j|d�y)Na�if 1:
            import os
            import threading
            import time
            import random

            def random_sleep():
                seconds = random.random() * 0.010
                time.sleep(seconds)

            class Sleeper:
                def __del__(self):
                    random_sleep()

            tls = threading.local()

            def f():
                # Sleep a bit so that the thread is still running when
                # Py_Finalize() is called.
                random_sleep()
                tls.x = Sleeper()
                random_sleep()

            threading.Thread(target=f).start()
            random_sleep()
        rrrJ�r2rLr
rrs     r�test_finalization_shutdownz&ThreadTests.test_finalization_shutdown s-����4(��d�3���C������c�"rc�T���tj��tj���j��j���fd�}tj|��}|j|jd�|j��j�|j|j��|j}|j|jd��d��j�|j|jtj��d�|j|j��|j�|j|j��|j|j�|j�y)Nc�p���j��j�tjd�y)N�{�G�z�?)r�r�rRrS��finish�starteds��rr�z'ThreadTests.test_tstate_lock.<locals>.fIs#����O�O���N�N���J�J�t�rrqrr�F)r��
allocate_lockr�r(rG�assertIs�_tstate_lockr�r�r�r�r�r
r�r�r�)r2r�r��tstate_lockr�r�s    @@r�test_tstate_lockzThreadTests.test_tstate_lockCs'����'�'�)���&�&�(����������	�

���A�&���
�
�a�n�n�d�+�	���	���������
�
��%��n�n������,�,�Q�,�7��?�����	
����+�+�G�4I�4I�+�J�E�R�	
����
�
��%������������&����!�.�.�)�	���rc�(���tj��tj���j��j���fd�}tj|��}|j��j�|j
dt|���j�d}td�D]&}|t|�vrntjd��(|j
|t|��|j�y)Nc�F���j��j�yr<)r�r�r�s��rr�z(ThreadTests.test_repr_stopped.<locals>.fls����O�O���N�N�rrqr��stoppedi�r�)
r�r�r�r(rGr�r�r�r�r�rRrSr�)r2r�r��LOOKING_FORr�r�r�s     @@r�test_repr_stoppedzThreadTests.test_repr_stoppedfs�����'�'�)���&�&�(����������	�
���A�&��	���	������
�
�i��a��)����� ���s��A��d�1�g�%���J�J�t���	
�
�
�k�4��7�+�	���rc�8�tdd�D�]}tj|�}t|�D�cgc]"}tj|j����$}}|D]}|j��|D]}|j
��t|�D�cgc]"}tj|j����$}}|D]}|j��|D]}|j
��|jt|j���ycc}wcc}w)Nr6r�rq)
r�r(r�rGr�r�r�r�r�
ValueError)r2�limit�bsrMr�r�s      r�test_BoundedSemaphore_limitz'ThreadTests.test_BoundedSemaphore_limit�s����1�b�\�E��+�+�E�2�B� %�e��.� ,�1�!�'�'�r�z�z�:� ,�
�.������	���������!&�e��.� ,�1�!�'�'�r�z�z�:� ,�
�.������	������������j�"�*�*�5�"��.��.s�'D�'Dc������fd��d����fd��d�_tj�}tj��	t	j��ddl}|j
��td�D]	}���	tj|�t	j|�y#tj|�t	j|�wxYw)Nc����Sr<rA��frame�eventr}�
noop_traces   �rr�z9ThreadTests.test_frame_tstate_tracing.<locals>.noop_trace��	����rc3�K�	d����w)N�	generatorrArArrr�z8ThreadTests.test_frame_tstate_tracing.<locals>.generator�s�����!�!��s�	c�^���j����_t�j�Sr<)�gen�next)�callbackr�s��rr�z7ThreadTests.test_frame_tstate_tracing.<locals>.callback�s%����|�|�#�(�{�������%�%rrrL)r�r�gettrace�settracer(�	_testcapi�call_in_temporary_c_threadr�)r2�	old_tracer�rr�r�r�s    @@@r�test_frame_tstate_tracingz%ThreadTests.test_frame_tstate_tracing�s����	�	"�	&�����L�L�N�	����Z� �	*����z�*�
��0�0��:��a����
�!�
�L�L��#����y�)��
�L�L��#����y�)�s
�AB0�0,Cc����fd��tj�}	tj��tj�}|j�|�tj|�y#tj|�wxYw)Nc����Sr<rAr�s   �rr�z-ThreadTests.test_gettrace.<locals>.noop_trace�r�r)r(r�r�rr)r2r��
trace_funcr�s   @r�
test_gettracezThreadTests.test_gettrace�sf���	��&�&�(�	�	*����z�*�"�+�+�-�J����Z�
�3����y�)��I���y�)�s�;A-�-Bc�����d�}tj�}tj��tj��g����fd�}	tj|��}|j	��j�tj|��j�|j�|j�d|g�|jtj�|�|jtj�|�tj|�|jtj�|�|jtj�|�y#tj|�wxYw)Nc��yr<rAr�s r�fnz1ThreadTests.test_gettrace_all_threads.<locals>.fn����trc�����jtj���j��j	��jtj��yr<)r�rr�r�r�)�first_check�second_check�trace_funcss���r�checkerz6ThreadTests.test_gettrace_all_threads.<locals>.checker�sA������s�|�|�~�.��O�O���������s�|�|�~�.rrq)r(r�r�rGr�r��settrace_all_threadsr�r�rrr)r2r�r�r�r�r�r�r�s     @@@r�test_gettrace_all_threadsz%ThreadTests.test_gettrace_all_threads�s�����&�&�(�	��o�o�'�� ���(����	/�	6�� � ��0�A�
�G�G�I������*�*�2�.�����
�F�F�H����[�4��*�5����Y�/�/�1�2�6����S�\�\�^�R�0��*�*�9�5�����+�+�-�y�9���������3��
�*�*�9�5��
�
CE2�2F	c��d�}tj�}	tj|�|j|tj��tj|�y#tj|�wxYw)Nc��yr<rAr�s rr�z'ThreadTests.test_getprofile.<locals>.fn�r�r)r(�
getprofile�
setprofilerr)r2r��old_profiles   r�test_getprofilezThreadTests.test_getprofile�s\����*�*�,��	.�� � ��$����R��!5�!5�!7�8�� � ��-��I� � ��-�s�9A(�(A?c�����d�}tj�}tj��tj��g����fd�}	tj|��}|j	��j�tj|��j�|j�|j�d|g�|jtj�|�|jtj�|�tj|�|jtj�|�|jtj�|�y#tj|�wxYw)Nc��yr<rAr�s rr�z3ThreadTests.test_getprofile_all_threads.<locals>.fn�r�rc�����jtj���j��j	��jtj��yr<)r�rr�r�r�)r��
profile_funcsr�s���rr�z8ThreadTests.test_getprofile_all_threads.<locals>.checker�sC���� � ����!1�2��O�O������� � ����!1�2rrq)r(r�r�rGr�r��setprofile_all_threadsr�r�rrr)r2r�r�r�r�r�r�r�s     @@@r�test_getprofile_all_threadsz'ThreadTests.test_getprofile_all_threads�s�����*�*�,���o�o�'�� ���(���
�	3�	:�� � ��0�A�
�G�G�I������,�,�R�0�����
�F�F�H����]�T�2�J�7����Y�1�1�3�R�8����S�^�^�-�r�2��,�,�[�9�����-�-�/��=�������)�;�7��
�,�,�[�9�r�c��dD]�}|j|��5tj�}tj|j|��}|j�|j}|s!|j|tj�n |j|tj�|j�|j�|j|tj�ddd���y#1swY��xYw)N)FTrG)rkr�)r�r(r�rGr�r�r�r��_shutdown_locksr�r�r�)r2r�r�rr�s     r�test_shutdown_lockszThreadTests.test_shutdown_lockss���#�F����V��,�!���)��"�)�)����F�K������$�1�1����M�M�+�y�/H�/H�I��$�$�[�)�2K�2K�L��	�	�����
�� � ��i�.G�.G�H�'-�,�$�,�,�s�CC8�8D	c�d�tdd�\}}}|j|j�d�y)Nra(if 1:
            import threading

            class Atexit:
                def __del__(self):
                    print("thread_dict.atexit = %r" % thread_dict.atexit)

            thread_dict = threading.local()
            thread_dict.atexit = "value"

            atexit = Atexit()
        sthread_dict.atexit = 'value')r	rr�rstripr	s    r�test_locals_at_exitzThreadTests.test_locals_at_exit#s4��(��/�
���C��	
�������'F�Grc���Gd�dt�}|�}tj|��}|j�|j	�|j|j�y)Nc��eZdZd�Zd�Zd�Zy)�6ThreadTests.test_boolean_target.<locals>.BooleanTargetc��d|_y�NF��ranr1s rr3z?ThreadTests.test_boolean_target.<locals>.BooleanTarget.__init__:s	�� ��rc��yr�rAr1s r�__bool__z?ThreadTests.test_boolean_target.<locals>.BooleanTarget.__bool__<s��rc��d|_y)NTr�r1s r�__call__z?ThreadTests.test_boolean_target.<locals>.BooleanTarget.__call__>s	����rN)r>r?r@r3r�r�rArr�
BooleanTargetr�9s��
!�
�
 rr�rq)rtr(rGr�r�r�r�)r2r�rkrs    r�test_boolean_targetzThreadTests.test_boolean_target4sI��
	 �F�	 �����!�!��0���������
�����
�
�#rc��d�}tj�5tj|��j	�ddd�y#1swYyxYw)Nc��yr<rArArr�noopz0ThreadTests.test_leak_without_join.<locals>.noopJrfrrq)rr�r(rGr�)r2r�s  r�test_leak_without_joinz"ThreadTests.test_leak_without_joinGs6��	�
�
/�
/�
1����D�)�/�/�1�2�
1�
1�s�%A�Ac��tjd�}td|�\}}}|j|d�|j|d�y)Na�
            import _thread
            import sys

            event = _thread.allocate_lock()
            event.acquire()

            def import_threading():
                import threading
                event.release()

            if 'threading' in sys.modules:
                raise Exception('threading is already imported')

            _thread.start_new_thread(import_threading, ())

            # wait until the threading module is imported
            event.acquire()
            event.release()

            if 'threading' not in sys.modules:
                raise Exception('threading is not imported')

            # don't wait until the thread completes
        rr)�textwrap�dedentr	rrrs     r�test_import_from_another_threadz+ThreadTests.test_import_from_another_threadOsK����� �
��2(��d�3���C������c�"�����c�"rc��d}td|�\}}}|j|j�d�|jd|�y)Na6if 1:
            import _thread

            def f():
                print("shouldn't be printed")

            class AtFinalization:
                def __del__(self):
                    print("OK")
                    _thread.start_new_thread(f, ())
            at_finalization = AtFinalization()
        r�OKs/can't create new thread at interpreter shutdown)r	rrrr�rKs     r�%test_start_new_thread_at_finalizationz1ThreadTests.test_start_new_thread_at_finalizationpsB����'�t�T�2���3���������e�,��
�
�H�#�NrN)F)9r>r?r@�maxDiffrrur�r�r�r�r�r�r�r�rr
rrrr2rArErHrrNr`rgr�
skipUnlessr�r[rprsr!rrrr
�
requires_forkrxrzr}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rArrrbrbws����G��=��=�4�6�D��D�".�H
(� 	 �	 �#�.U�p
<�#!�J�<#�(0�"N�B&�>)�"��#��#�>�;��;�,���X�����Y�/�1J�K�3�L��3�2��X�����Y�/�1J�K�%�L��%�N�X�_�_�S�\�\�%6�6�8M�N��W�����X�����Y�/�1J�K�<7�L��O�<7�|P�5�:!#�F!�F�66�$�&*��&*�P
*�4�:.�8�:�I��I�.H�"$�&2�#�BOrrbc��eZdZd�Zd�Zed��Zed��Zeje
jevd�d��Z
d�Zed��Zed	��Zy
)�ThreadJoinOnShutdownc��d|z}td|�\}}}|j�jdd�}|j|d�y)Na�if 1:
            import sys, os, time, threading

            # a thread, which waits for the main program to terminate
            def joiningfunc(mainthread):
                mainthread.join()
                print('end of thread')
                # stdout is fully buffered because not a tty, we have to flush
                # before exit.
                sys.stdout.flush()
        
rrjrozend of main
end of thread
rk)r2�scriptr
rrros      r�
_run_and_joinz"ThreadJoinOnShutdown._run_and_join�sP��
��
��(��f�5���C���z�z�|�#�#�D�"�-������=�>rc�*�d}|j|�y)Nz�if 1:
            import os
            t = threading.Thread(target=joiningfunc,
                                 args=(threading.current_thread(),))
            t.start()
            time.sleep(0.1)
            print('end of main')
            �r��r2r�s  r�test_1_join_on_shutdownz,ThreadJoinOnShutdown.test_1_join_on_shutdown�s����	
���6�"rc�*�d}|j|�y)Na�if 1:
            from test import support

            childpid = os.fork()
            if childpid != 0:
                # parent process
                support.wait_process(childpid, exitcode=0)
                sys.exit(0)

            # child process
            t = threading.Thread(target=joiningfunc,
                                 args=(threading.current_thread(),))
            t.start()
            print('end of main')
            r�r�s  r�test_2_join_in_forked_processz2ThreadJoinOnShutdown.test_2_join_in_forked_process�s����	
���6�"rc�*�d}|j|�y)Na�if 1:
            from test import support

            main_thread = threading.current_thread()
            def worker():
                childpid = os.fork()
                if childpid != 0:
                    # parent process
                    support.wait_process(childpid, exitcode=0)
                    sys.exit(0)

                # child process
                t = threading.Thread(target=joiningfunc,
                                     args=(main_thread,))
                print('end of main')
                t.start()
                t.join() # Should not block: main_thread is already stopped

            w = threading.Thread(target=worker)
            w.start()
            r�r�s  r�!test_3_join_in_forked_from_threadz6ThreadJoinOnShutdown.test_3_join_in_forked_from_thread�s��
��*	
���6�"rrtc��tjd��r|jd�d}td|�\}}}|j	|�y)NTrra�if True:
            import os
            import random
            import sys
            import time
            import threading

            thread_has_run = set()

            def random_io():
                '''Loop for a while sleeping random tiny amounts and doing some I/O.'''
                import test.test_threading as mod
                while True:
                    with open(mod.__file__, 'rb') as in_f:
                        stuff = in_f.read(200)
                        with open(os.devnull, 'wb') as null_f:
                            null_f.write(stuff)
                            time.sleep(random.random() / 1995)
                    thread_has_run.add(threading.current_thread())

            def main():
                count = 0
                for _ in range(40):
                    new_thread = threading.Thread(target=random_io)
                    new_thread.daemon = True
                    new_thread.start()
                    count += 1
                while len(thread_has_run) < count:
                    time.sleep(0.001)
                # Trigger process shutdown
                sys.exit(0)

            main()
            r)r
rrr	r��r2r�r
rrs     r�test_4_daemon_threadsz*ThreadJoinOnShutdown.test_4_daemon_threads�sK��
�"�"�$�/�
�M�M�9�:�!��D(��f�5���C������rc��d}td|�\}}}|j|d�|j|j�d�|j|d�y)Na�if True:
            import threading
            import time

            def thread2():
                time.sleep(0.05)
                print("OK")

            def thread1():
                time.sleep(0.05)
                t2 = threading.Thread(target=thread2)
                t2.start()

            t = threading.Thread(target=thread1)
            t.start()
            # do not join() -- the interpreter waits for non-daemon threads to
            # finish.
            rrr�rrr�s     r�test_thread_from_threadz,ThreadJoinOnShutdown.test_thread_from_thread�sS����$(��f�5���C������c�"��������e�,�����Q�rc�,�d�}tjtd��5g}td�D]9}t	j
|��}|j
|�|j��;|D]}|j��	ddd�y#1swYyxYw)Nc��tj�}|dkDrtj|d��ytjd�y)Nr�2rW)r[r\r
r^r])r_s r�do_fork_and_waitzIThreadJoinOnShutdown.test_reinit_tls_after_fork.<locals>.do_fork_and_waits/���'�'�)�C��Q�w��$�$�S�2�6�����rrRrS�rq)	rYrZr5r�r(rGr�r�r�)r2r�r�r�r�s     r�test_reinit_tls_after_forkz/ThreadJoinOnShutdown.test_reinit_tls_after_forks}��
	��
$�
$�.@�,4�6��G��2�Y���$�$�,<�=�����q�!����	��
�������6�6�6�s�A!B
�
Bc�X�g}td�D]:}tjd���}|j|�|j	��<	tjtd��5tj�}|dk(rLttj��dk(rtjd�n-tjd	�ntj|d�
�ddd�|D]}|j!��y#1swY�!xYw#|D]}|j!��wxYw)Nr�c�,�tjd�S)Ng333333�?)rRrSrArrr~zKThreadJoinOnShutdown.test_clear_threads_states_after_fork.<locals>.<lambda>8s�����C�rrqrRrSrr6�3�4rW)r�r(rGr�r�rYrZr5r[r\r�r�_current_framesr]r
r^r�)r2r�r�r�r_s     r�$test_clear_threads_states_after_forkz9ThreadJoinOnShutdown.test_clear_threads_states_after_fork1s���
���r��A�� � �(@�A�A��N�N�1��
�G�G�I��
	��(�(�2D�08�:��g�g�i���!�8��3�.�.�0�1�Q�6������������(�(��r�:�:��������:�:���������s%�D�'A=D�$D�D
�	D�D)N)r>r?r@r�r�rr�r�rr!rrrr�r�r�rrArrr�r��s���?�"
#��#��#�&�#��#�6�X�_�_�S�\�\�%6�6�8M�N�,�O�,�\ �0����2���rr�c�p�eZdZd�Zd�Zd�Zed��Zed��Z	d
dddd�d	�Z
ed
��Zed��Zy)�SubinterpThreadingTestsc��tj�\}}|jtj|�|jtj|�t	td�rtj
|d�||fS)N�set_blockingF)r[�piper&�closer�r)r2�r�ws   rrzSubinterpThreadingTests.pipeOsV���w�w�y���1�������!�$�������!�$��2�~�&��O�O�A�u�%��1�v�
rc�
�|j�\}}tjd|fz�}tjj|�}|j
|d�|j
tj|d�d�y)Na�
            import os
            import random
            import threading
            import time

            def random_sleep():
                seconds = random.random() * 0.010
                time.sleep(seconds)

            def f():
                # Sleep a bit so that the thread is still running when
                # Py_EndInterpreter is called.
                random_sleep()
                os.write(%d, b"x")

            threading.Thread(target=f).start()
            random_sleep()
        rr6�x�	rr�r�rr
�run_in_subinterprrr[�read�r2r
rrLr�s     r�test_threads_joinz)SubinterpThreadingTests.test_threads_joinWsr���y�y�{���1���� �$�d�% ���&�l�l�+�+�D�1������a� ��������A���-rc�
�|j�\}}tjd|fz�}tjj|�}|j
|d�|j
tj|d�d�y)Na�
            import os
            import random
            import threading
            import time

            def random_sleep():
                seconds = random.random() * 0.010
                time.sleep(seconds)

            class Sleeper:
                def __del__(self):
                    random_sleep()

            tls = threading.local()

            def f():
                # Sleep a bit so that the thread is still running when
                # Py_EndInterpreter is called.
                random_sleep()
                tls.x = Sleeper()
                os.write(%d, b"x")

            threading.Thread(target=f).start()
            random_sleep()
        rr6r
rrs     r�test_threads_join_2z+SubinterpThreadingTests.test_threads_join_2ssr��
�y�y�{���1���� �2�d�3 ���4�l�l�+�+�D�1������a� ��������A���-rc��|j�\}}d}d}d}tj�}|jd|�d|�d|�d|�d|�d|�d�
�|j	�|jt
j|d	�|�|jt
j|d	�|�|jt
j|d	�|�y)
N�I�F�Dz�if True:
            import os
            import threading
            import time

            done = False

            def notify_fini():
                global done
                done = True
                os.write(z, z�)
                t.join()
            threading._register_atexit(notify_fini)

            def task():
                while not done:
                    time.sleep(0.1)
                os.write(z\)
            t = threading.Thread(target=task)
            t.start()

            os.write(�)
            r6)rr�createrVr	rrr[r)r2�r_interp�w_interp�INTERP�FINI�DONE�interps       r�test_threads_join_with_no_mainz6SubinterpThreadingTests.test_threads_join_with_no_main�s���!�Y�Y�[���(��������$�$�&���
�
�
�#��2�d�X�.�#��2�d�X�.��Z�r�&��,
�+�	�.	�����������1�-�v�6��������1�-�t�4��������1�-�t�4rc��dtjj�d�}d|�d�}tjj�5t	d|�\}}}ddd�|jdj
��y#1swY�*xYw)Nz�if 1:
            import os
            import threading
            import time

            def f():
                # Make sure the daemon thread is still running when
                # Py_EndInterpreter is called.
                time.sleep(zJ)
            threading.Thread(target=f, daemon=True).start()
            zKif 1:
            import _testcapi

            _testcapi.run_in_subinterp(rrz:Fatal Python error: Py_EndInterpreter: not the last thread)rr
r��SuppressCrashReportr
r�rl)r2�subinterp_coder�r
rrs      r�test_daemon_threads_fatal_errorz7SubinterpThreadingTests.test_daemon_threads_fatal_error�s}���!�L�L�6�6�7�8
�
��"�	$��
�\�\�
-�
-�
/�0��v�>�L�B��S�0��
�
�,�-0�Z�Z�\�	;�0�
/�s�A=�=BTF��allowed�daemon_allowedr�c	�<�tjd|�d|�d��}tjd|�d|�d|�d��}tjj	�5td|�\}}}ddd�|j
�S#1swYj
�SxYw)	Nz�
            import test.support
            import threading
            def func():
                print('this should not have run!')
            t = threading.Thread(target=func, daemon=rz#
            t.start()
            zh
            import test.support
            test.support.run_in_subinterp_with_config(
                z�,
                use_main_obmalloc=True,
                allow_fork=True,
                allow_exec=True,
                allow_threads=z',
                allow_daemon_threads=zp,
                check_multi_interp_extensions=False,
                own_gil=False,
            )
            r)r�r�rr
r#r	rl)	r2�before_startr'r(r�r$r�rMrs	         r�_check_allowedz&SubinterpThreadingTests._check_allowed�s���
"���.6�
7=�X�>
�
�N�
�
*������&� �"�#� '�i�(&�&4�%5�6
�"����\�\�
-�
-�
/�(��v�6�I�A�q�#�0��z�z�|��0��z�z�|��s�B�Bc�P�|jddd��}|jd|�y)NFr&�RuntimeError)r+r��r2rs  r�test_threads_not_allowedz0SubinterpThreadingTests.test_threads_not_allowed�s0���!�!�� ��"�
��
	
�
�
�n�c�*rc�6�|jd�5|jddd��}|jd|�ddd�|jd�5|jdddd��}|jd|�ddd�y#1swY�KxYw#1swYyxYw)Nzvia Thread()TFr&r-zvia Thread.daemon setterzt.daemon = True)r�r+r�r.s  r�test_daemon_threads_not_allowedz7SubinterpThreadingTests.test_daemon_threads_not_allowed�s���
�\�\�.�
)��%�%��$��&��C�

�M�M�.�#�.�
*��\�\�4�
5��%�%�!��$��	&��C�
�M�M�.�#�.�6�
5�*�
)��6�
5�s�'B�(B�B�BN)ro)
r>r?r@rrrr#r!rr%r+r/r1rArrrrNsv���.�8#.�J�#5��#5�J�;��;�,�#�&*�#��>�+��+��/��/rrc�h�eZdZd�Zd�Zd�Zd�Zd�Ze�d��Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zy
)�ThreadingExceptionTestsc��tj�}|j�|jt|j�|j�yr<)r(rGr�rr-r��r2rs  r�test_start_thread_againz/ThreadingExceptionTests.test_start_thread_agains6���!�!�#���������,����5����
rc�l�tj�}|jt|j�yr<)r(r�rr-r�)r2r�s  r�test_joining_current_threadz3ThreadingExceptionTests.test_joining_current_threads&��"�1�1�3�����,��(;�(;�<rc�l�tj�}|jt|j�yr<)r(rGrr-r�r5s  r�test_joining_inactive_threadz4ThreadingExceptionTests.test_joining_inactive_threads$���!�!�#�����,����4rc��tj�}|j�|jtt
|dd�|j
�yrC)r(rGr�rr-r'r�r5s  r�test_daemonize_active_threadz4ThreadingExceptionTests.test_daemonize_active_thread"s8���!�!�#���������,����4�H����
rc�l�tj�}|jt|j�yr<)r(r�rr-r�r�s  r�test_releasing_unacquired_lockz6ThreadingExceptionTests.test_releasing_unacquired_lock(s"���~�~������,����5rc�|�d}d}tjtjd|gtjtj��}|j�\}}|j
�jdd�}|j|jdd|j
�z�|j||�y)	Naif True:
            import threading

            def recurse():
                return recurse()

            def outer():
                try:
                    recurse()
                except RecursionError:
                    pass

            w = threading.Thread(target=outer)
            w.start()
            w.join()
            print('end of main thread')
            zend of main thread
r)�stdout�stderrrjrorzUnexpected error: )
�
subprocess�Popenr�
executable�PIPE�communicaterlrmrr�
returncode)r2r��expected_output�pr@rAros       r�test_recursion_limitz,ThreadingExceptionTests.test_recursion_limit,s�����"1�����c�n�n�d�F�;�$.�O�O�J�O�O�
M����������}�}��&�&�t�R�0��������q�*>�����*P�Q������/rc��d}td|�\}}}|j|d�|j�}|jd|�|jd|�|jd|�|j	d|�y)Na�if True:
            import threading
            import time

            running = False
            def run():
                global running
                running = True
                while running:
                    time.sleep(0.01)
                1/0
            t = threading.Thread(target=run)
            t.start()
            while not running:
                time.sleep(0.01)
            running = False
            t.join()
            rr�Exception in thread�"Traceback (most recent call last):�ZeroDivisionError�Unhandled exception�r	rrrlr�r�r�s     r�test_print_exceptionz,ThreadingExceptionTests.test_print_exceptionLsv����$(��f�5���C������c�"��j�j�l���
�
�+�S�1��
�
�:�C�@��
�
�)�3�/����.��4rc��d}td|�\}}}|j|d�|j�}|jd|�|jd|�|jd|�|j	d|�y)Na�if True:
            import sys
            import threading
            import time

            running = False
            def run():
                global running
                running = True
                while running:
                    time.sleep(0.01)
                1/0
            t = threading.Thread(target=run)
            t.start()
            while not running:
                time.sleep(0.01)
            sys.stderr = None
            running = False
            t.join()
            rrrLrMrNrOrPr�s     r�%test_print_exception_stderr_is_none_1z=ThreadingExceptionTests.test_print_exception_stderr_is_none_1gsv����((��f�5���C������c�"��j�j�l���
�
�+�S�1��
�
�:�C�@��
�
�)�3�/����.��4rc��d}td|�\}}}|j|d�|jd|j��y)Na�if True:
            import sys
            import threading
            import time

            running = False
            def run():
                global running
                running = True
                while running:
                    time.sleep(0.01)
                1/0
            sys.stderr = None
            t = threading.Thread(target=run)
            t.start()
            while not running:
                time.sleep(0.01)
            running = False
            t.join()
            rrrO)r	rrr�rlr�s     r�%test_print_exception_stderr_is_none_2z=ThreadingExceptionTests.test_print_exception_stderr_is_none_2�sD����((��f�5���C������c�"����.��
�
��=rc� �d}td|�y)Na9if True:
            import time
            import threading
            import _thread

            def f():
                try:
                    f()
                except RecursionError:
                    f()

            def g():
                try:
                    raise ValueError()
                except* ValueError:
                    f()

            def h():
                time.sleep(1)
                _thread.interrupt_main()

            t = threading.Thread(target=h)
            t.start()
            g()
            t.join()
            r)r
r�s  r�test_print_exception_gh_102056z6ThreadingExceptionTests.test_print_exception_gh_102056�s����6	�d�F�+rc���d��G�fd�dtj�}|�}|j�|j�|j	|j
�|j
|j
t�d|_y)Nc���r<rArArr�
bare_raisezOThreadingExceptionTests.test_bare_raise_in_brand_new_thread.<locals>.bare_raise�s��rc���eZdZdZ�fd�Zy)�OThreadingExceptionTests.test_bare_raise_in_brand_new_thread.<locals>.Issue27558Nc�P��	��y#t$r}||_Yd}~yd}~wwxYwr<)r��exc)r2r^rZs  �rrVzSThreadingExceptionTests.test_bare_raise_in_brand_new_thread.<locals>.Issue27558.run�s&���#��L�� �#�"�D�H�H��#�s��	%� �%)r>r?r@r^rV)rZs�r�
Issue27558r\�s
����C�
#rr_)r(rGr�r�r�r^r�r-)r2r_rrZs   @r�#test_bare_raise_in_brand_new_threadz;ThreadingExceptionTests.test_bare_raise_in_brand_new_thread�sb���	�	#��)�)�	#�����������
����V�Z�Z�(����f�j�j�,�7���
rc��d�}|jtjtj�t	d�D�cgc]}tj|����}}|D]"}|j�|j��$ycc}w)Nc��ttjdd��5}|jd�t	j
�ddd�y#1swYyxYw)Nrrr)�encoding� )�openr�TESTFN�write�	traceback�format_stack)�fps r�modify_filezQThreadingExceptionTests.test_multithread_modify_file_noerror.<locals>.modify_file�s9���i�&�&��g�>�"�����
��&�&�(�?�>�>�s�&A�Arrq)	r&r�unlinkrfr�r(rGr�r�)r2rkr�r�r�s     r�$test_multithread_modify_file_noerrorz<ThreadingExceptionTests.test_multithread_modify_file_noerror�sw��	)�
	
���	�(�(�)�*:�*:�;��3�Z�
���
���K�0��	�
��A�
�G�G�I�
�F�F�H���	
s�BN)r>r?r@r6r8r:r<r>rrJrQrSrUrWr`rmrArrr3r3sP���>�5��6���0��0�>5�65�:>�2,�>�*rr3c��eZdZd�Zy)�
ThreadRunFailc��td��)N�
run failed�r�r1s rrVzThreadRunFail.run�s
����&�&rNr�rArrroro�s��'rroc�`��eZdZ�fd�Zd�Zejd��Zd�Zd�Z	d�Z
d�Z�xZS)�ExceptHookTestsc�8��t|�t�|�	�yr<)r+�superr\)r2�	__class__s �rr\zExceptHookTests.setUp�s���"�4�(�
��
�rc��tjd�5}td��}|j�|j	�ddd�j�j
�}|jdj�d�|�|jd|�|jd|�|jd|�y#1swY�~xYw)	NrA�excepthook threadrE�Exception in thread �:
�#Traceback (most recent call last):
z   raise ValueError("run failed")zValueError: run failed)	r
�captured_outputror�r��getvaluerr�rF)r2rArs   r�test_excepthookzExceptHookTests.test_excepthook�s���
�
$�
$�X�
.�&�"�(;�<�F��L�L�N��K�K�M�/�
���"�(�(�*���
�
�,�V�[�[�M��=�v�F��
�
�<�f�E��
�
�8�&�A��
�
�.��7�/�
.�s�-C�C	c�.�tjd�5}	td��#t$rU}t	j
gt
j��d��}	t	j|�d}n#d}wxYwYd}~nd}~wwxYw	ddd�n#1swYnxYwj�j�}|jdt	j��d�|�|jd|�|jd|�|jd|�y)NrA�bugrzr{r|z  raise ValueError("bug")zValueError: bug)
r
r}r�r�r(�ExceptHookArgsr�exc_infor%r~rr�r�)r2rAr^r�s    r�test_excepthook_thread_Nonez+ExceptHookTests.test_excepthook_thread_None�s����
$�
$�X�
.�&�
 � ��'�'���
 � �/�/�0G�#�,�,�.�0G�$�0G�H�� ��(�(��.� �D��4�D��D��

 ���/�
.�
.�����"�(�(�*���
�
�,�Y�-@�-@�-B�,C�3�G��P��
�
�<�f�E��
�
�1�6�:��
�
�'��0sC�B�#�	B�+A<�A0�-A<�0A4�4A<�7B�<B�B�Bc��Gd�dtj�}tjd�5}|�}|j	�|j�ddd�|j
j�d�y#1swY�*xYw)Nc��eZdZd�Zy)�4ExceptHookTests.test_system_exit.<locals>.ThreadExitc�.�tjd�yr5)r�exitr1s rrVz8ExceptHookTests.test_system_exit.<locals>.ThreadExit.runs
������rNr�rArr�
ThreadExitr�s��
rr�rAro)r(rGr
r}r�r�rrr~)r2r�rArs    r�test_system_exitz ExceptHookTests.test_system_exit
sf��	��)�)�	�
�
$�
$�X�
.�&��\�F��L�L�N��K�K�M�/�
	
������*�B�/�/�
.�s�(B�B	c���d��fd�}	tjtd|�5t�}|j	�|j�ddd�|j
�jt�|j
t�j�d�|j
�j�jj�|j�j�d�y#1swY��xYw#d�wxYw)Nc�
��|�yr<rA)�	hook_argsr�s �r�hookz4ExceptHookTests.test_custom_excepthook.<locals>.hooks����Drr%rq)r
�	swap_attrr(ror�r�rr�exc_typer�rx�	exc_value�
exc_traceback�
__traceback__r�r)r2r�rr�s   @r�test_custom_excepthookz&ExceptHookTests.test_custom_excepthooks������	�	��"�"�9�l�D�A�&����������
�B�

���T�]�]�J�7����S����0�,�?����T�/�/����1M�1M�N��M�M�$�+�+�v�.��D�B�A���D�s#�C8�+C,�BC8�,C5�1C8�8C<c����d�}d��fd�}tjtd|�5tjtd|�5tjd�5}t�}|j
�|j�ddd�ddd�ddd�|jj�d�|j�d�y#1swY�LxYw#1swY�PxYw#1swY�TxYw)Nc��td��)N�threading_hook failedrrr�s r�threading_hookzCExceptHookTests.test_custom_excepthook_fail.<locals>.threading_hook0s���4�5�5rc���t|��yr<ry)r�r�r��err_strs   �r�sys_hookz=ExceptHookTests.test_custom_excepthook_fail.<locals>.sys_hook5s����)�n�Grr%rAz#Exception in threading.excepthook:
r�)
r
r�r(rr}ror�r�rrr~)r2r�r�rArr�s     @r�test_custom_excepthook_failz+ExceptHookTests.test_custom_excepthook_fail/s����	6���	%��
�
�y�,��
G�
�
�
�s�L�(�
;�
�
$�
$�X�
.�&�"�_�F��L�L�N��K�K�M�/�<�H�	
������*�?�	A�����"9�:�/�
.��<�
;��H�
G�s;�C'�C�+C�C�C'�C�C�C$	� C'�'C0c�8�d�}d�}|�}tjtd|�5|�}tjt_|�}ddd�|j|�|j
|�|j|d�y#1swY�@xYw)Nc���tjd�5}td��}|j�|j	�ddd�|j�S#1swYj�SxYw)NrAryrE)r
r}ror�r�r~)�outputrs  r�
run_threadz<ExceptHookTests.test_original_excepthook.<locals>.run_threadEsX���(�(��2�f�&�,?�@���������
�3��?�?�$�$�	3��?�?�$�$�s�-A�A3c�:�tdtj��y)NzRunning a thread failed)�file)rPrrAr�s rr�z@ExceptHookTests.test_original_excepthook.<locals>.threading_hookLs���+�#�*�*�=rr%zRunning a thread failed
)r
r�r(r)r%rrr�)r2r�r��default_output�custom_hook_output�recovered_outputs      r�test_original_excepthookz(ExceptHookTests.test_original_excepthookDs���	%�	>�$���
�
�
�y�,��
G�!+���#,�#;�#;�I� �)�|��H�
	
����)9�:����N�,>�?����+�-H�I�H�
G�s�(B�B)
r>r?r@r\rr
rr�r�r�r�r��
__classcell__)rws@rrtrt�s<����
8�
���1��1�(0��*;�*Jrrtc��eZdZd�Zd�Zd�Zy)�
TimerTestsc�n�tj|�g|_tj�|_yr<)rXr\�
callback_argsr(r��callback_eventr1s rr\zTimerTests.setUp\s'�����4� ����'�o�o�/��rc��tjd|j�}|j�|jj�|jjd�d|jd<|jj�tjd|j�}|j�|jj�|jt|j�d�|j|jdifdifg�|j�|j�y)Nr��blah�bar�foormrA)r(�Timer�
_callback_spyr�r�r�r�r�r#�clearrrr�r�r�)r2�timer1�timer2s   r� test_init_immutable_default_argsz+TimerTests.test_init_immutable_default_argsas�������t�'9�'9�:��������� � �"������6�"�$��
�
�e�����!�!�#�����t�'9�'9�:��������� � �"�����T�/�/�0�!�4�����+�+�r�2�h��R��-A�B����
����
rc��|jj|dd|j�f�|jj	�yr<)r�r��copyr�r�)r2r�r#s   rr�zTimerTests._callback_spyrs7�����!�!�4��7�F�K�K�M�":�;������!rN)r>r?r@r\r�r�rArrr�r�Zs��0�
�""rr�c�0�eZdZeej
�Zy)�	LockTestsN)r>r?r@�staticmethodr(r��locktyperArrr�r�vs���I�N�N�+�Hrr�c�0�eZdZeej
�Zy)�PyRLockTestsN)r>r?r@r�r(�_PyRLockr�rArrr�r�ys���I�.�.�/�Hrr�zRLock not implemented in Cc�0�eZdZeej
�Zy)�CRLockTestsN)r>r?r@r�r(�_CRLockr�rArrr�r�|s���I�-�-�.�Hrr�c�0�eZdZeej
�Zy)�
EventTestsN)r>r?r@r�r(r��	eventtyperArrr�r��s���Y�_�_�-�Irr�c�6�eZdZeej
�Zd�Zy)�ConditionAsRLockTestsc�&�|jd�y)Nz,Condition does not expose _recursion_count())rr1s r�test_recursion_countz*ConditionAsRLockTests.test_recursion_count�s���
�
�D�ErN)r>r?r@r�r(r;r�r�rArrr�r��s���I�/�/�0�H�Frr�c�0�eZdZeej
�Zy)�ConditionTestsN)r>r?r@r�r(r;�condtyperArrr�r��s���I�/�/�0�Hrr�c�0�eZdZeej
�Zy)�SemaphoreTestsN)r>r?r@r�r(�	Semaphore�semtyperArrr�r��s���9�.�.�/�Grr�c�0�eZdZeej
�Zy)�BoundedSemaphoreTestsN)r>r?r@r�r(r�r�rArrr�r��s���9�5�5�6�Grr�c�0�eZdZeej
�Zy)�BarrierTestsN)r>r?r@r�r(�Barrier�barriertyperArrr�r��s���y�0�0�1�Krr�c�,�eZdZd�Ze�d��Zy)�MiscTestCasec�d�t|�dh}ddh}tj|td||��y)Nr�r>r=)r(r�)�extra�not_exported)r+r
�check__all__r()r2r�r�s   r�test__all__zMiscTestCase.test__all__�s6��"�4�(����'��7�����T�9�.F�#(�|�	Erc��tj�5}d}ddl}|jj	||dz�}t|d�5}|j
d�ddd�d}tdd|�d	|�d
|�d|�d|jd
��d��\}}}	|j||�|j|	d�ddd�y#1swY�gxYw#1swYyxYw)N�_thread_fakerz.pyrz�if True:
                    import _thread
                    globals().update(vars(_thread))
                    del _is_main_interpreter
                    ssuccess!rzGif True:
                import sys
                sys.path.insert(0, z)
                import z*
                sys.modules['_thread'] = z!
                del sys.modules[z:]

                import threading
                print(rrz, end='')
                r)
r�temp_dir�os.path�pathr�rergr	rlrr)
r2�tempdir�modnamer[�filename�outfilerHrMrrs
          r�2test_gh112826_missing__thread__is_main_interpreterz?MiscTestCase.test_gh112826_missing__thread__is_main_interpreter�s���
�
�
�
!�W�$�G���w�w�|�|�G�W�u�_�=�H��h��$���
�
���%�*�O�*�4�6$�$+�;�/��y�!*�*1��3!�!(��,�'�-�-�g�6�9�:�	2�	�K�A�s�C�
���S�/�2����S�#�&�1"�
!�%�$��	"�
!�s$�2C�B?�AC�?C	�C�CN)r>r?r@r�rr�rArrr�r��s��E���'��'rr�c�Z�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	e
jd��Zy	)
�InterruptMainTestsc���d�}tj||�}|jtj||�|jt�5t	j
�ddd�y#1swYyxYw)Nc��ddzy)Nr6rrA)�signumr�s  r�handlerzLInterruptMainTests.check_interrupt_main_with_signal_handler.<locals>.handler�s	��
�a�Cr)�signalr&rrNr��interrupt_main)r2r�r��old_handlers    r�(check_interrupt_main_with_signal_handlerz;InterruptMainTests.check_interrupt_main_with_signal_handler�sT��	��m�m�F�G�4������
�
�v�{�;�
�
�
�0�
1��"�"�$�2�
1�
1�s�A.�.A7c�v�tj|�}	tj|tj�tj|�tj|tj
�tj|�tj||�y#tj||�wxYwr<)r��	getsignal�SIG_IGNr�r��SIG_DFL)r2r�r�s   r�check_interrupt_main_noerrorz/InterruptMainTests.check_interrupt_main_noerror�sv���"�"�6�*��		+��M�M�&�&�.�.�1��"�"�6�*��M�M�&�&�.�.�1��"�"�6�*�
�M�M�&�'�*��F�M�M�&�'�*�s�A2B � B8c���d�}tj|��}|jt�5|j	�|j�ddd�|j�y#1swY�xYw)Nc�,�tj�yr<)r�r�rArr�call_interruptzHInterruptMainTests.test_interrupt_main_subthread.<locals>.call_interrupt�s���"�"�$rrq)r(rGr�KeyboardInterruptr�r�)r2r�r�s   r�test_interrupt_main_subthreadz0InterruptMainTests.test_interrupt_main_subthread�sQ��	%����N�3��
�
�
�0�
1�
�G�G�I�
�F�F�H�2�	
����2�
1�s�!A)�)A2c��|jt�5tj�ddd�y#1swYyxYwr<)rr�r�r�r1s r�test_interrupt_main_mainthreadz1InterruptMainTests.test_interrupt_main_mainthread�s+���
�
�0�
1��"�"�$�2�
1�
1�s�4�=c��|jtj�|jtj�yr<)r�r��SIGINT�SIGTERMr1s r�'test_interrupt_main_with_signal_handlerz:InterruptMainTests.test_interrupt_main_with_signal_handler�s&���5�5�f�m�m�D��5�5�f�n�n�Erc��|jtj�|jtj�yr<)r�r�rrr1s r�test_interrupt_main_noerrorz.InterruptMainTests.test_interrupt_main_noerror�s&���)�)�&�-�-�8��)�)�&�.�.�9rc��|jttjd�|jttjtj
�|jttjd�y)Nr�i@B)rr�r�r�r��NSIGr1s r�"test_interrupt_main_invalid_signalz5InterruptMainTests.test_interrupt_main_invalid_signal�sN�����*�g�&<�&<�b�A����*�g�&<�&<�f�k�k�J����*�g�&<�&<�g�Frc���dg}dg}dg}d�}tj||||f��}|j�|ds	|ds�d|d<|j�|j	|d�y)NTFc�F�d}d|d<|dr|r|dz}ny	|dr�d|d<y)Ni�Trr6rA)r��cont�interrupted�
iterationss    r�workerzAInterruptMainTests.test_can_interrupt_tight_loops.<locals>.worker�s=��$�J��G�A�J��q�'���!�O�J����q�'�"�K��Nrr�r)r(rGr�r�r�)r2r
r�rr
r�s      r�test_can_interrupt_tight_loopsz1InterruptMainTests.test_can_interrupt_tight_loops�su���v���'���g��		"�
���F��$��0L�M��	���	��!�*���!�*���Q��	��������A��'rN)
r>r?r@r�r�r�r�rrrr�reap_threadsrrArrr�r��sA��%�+�	�%�F�:�G�
�"�"�(�#�(rr�c��eZdZd�Zd�Zd�Zy)�AtexitTestsc��tdd�\}}}|j|�|j|j�d�y)Nrz�if True:
            import threading

            def run_last():
                print('parrot')

            threading._register_atexit(run_last)
        sparrot)r	r�rrrr	s    r�test_atexit_outputzAtexitTests.test_atexit_outputs?��'��/�
���C��	
������������i�0rc�F�tdd�\}}}|j|�y)NraNif True:
            import threading
            from unittest.mock import Mock

            mock = Mock()
            threading._register_atexit(mock)
            mock.assert_not_called()
            # force early shutdown to ensure it was called once
            threading._shutdown()
            mock.assert_called_once()
        )r	r�r	s    r�test_atexit_called_oncez#AtexitTests.test_atexit_called_onces)��'��
/�

���C��	
����rc��tdd�\}}}|j|�|jd|j��y)Nrz�if True:
            import threading

            def func():
                pass

            def run_last():
                threading._register_atexit(func)

            threading._register_atexit(run_last)
        z2RuntimeError: can't register atexit after shutdown)r	r�r�rlr	s    r�test_atexit_after_shutdownz&AtexitTests.test_atexit_after_shutdown+sA��(��
/�

���C��	
������
�
�J��
�
��	rN)r>r?r@rrrrArrrr
s��1�
�rr�__main__)A�test.supportrrrrrr�test.support.import_helperr�test.support.script_helperr	r
rOrr�r(rRrr+r[rBr�r�rhrYrrr
r�ModuleNotFoundError�requires_working_threadingrrr#r+rtr-rGrC�TestCaserXrbr�rr3rortr�r��
RLockTestsr�r!r�r�r�r�r�r�r�r�r�r�rr>rerArr�<module>r sX����>�9�9�4�N�
�
������	��
��������)�,��+�+�4�8�+��	�=�4��f��<��!�!�<�B%�8�$�$�%�HO�,�HO�T J�<�J�Z@/�l�@/�FN�l�N�b'�I�$�$�'�
pJ�l�pJ�f"��"�8,�
�$�$�,�0�:�(�(�0������"�"�d�*�,H�I�/�*�'�'�/�J�/�.��&�&�.�F�J�1�1�F�1�Z�.�.�1�0�Z�.�.�0�7�J�<�<�7�2�:�*�*�2�#'�8�$�$�#'�LM(��*�*�M(�`/�(�#�#�/�d�z���H�M�M�O���AA���L��s�-I�I�I

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists