Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_threading.cpython-34.pyc

�
f f��@s�dZddlZddlmZmZmZmZddlmZm	Z	ddl
Z
ddlZddlZed�Z
ed�ZddlZddlZddlZddlZddlZddlmZdd	d
ddfZGd
d�de�ZGdd�dej�ZGdd�dej�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�dej!�Z!Gdd �d ej"�Z#ej$ej%dkd!�Gd"d#�d#ej"��Z&Gd$d%�d%ej'�Z'Gd&d'�d'ej"�Z(Gd(d)�d)ej)�Z)Gd*d+�d+ej*�Z*Gd,d-�d-ej+�Z+Gd.d/�d/ej,�Z,e-d0kr�ej.�ndS)1z!
Tests for the threading module.
�N)�verbose�strip_python_stderr�
import_module�cpython_only)�assert_python_ok�assert_python_failure�_thread�	threading)�
lock_testsZfreebsd4Zfreebsd5Zfreebsd6Znetbsd5zhp-ux11c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�CountercCs
d|_dS)Nr)�value)�self�r�8/opt/alt/python34/lib64/python3.4/test/test_threading.py�__init__!szCounter.__init__cCs|jd7_dS)N�)r)r
rrr�inc#szCounter.inccCs|jd8_dS)Nr)r)r
rrr�dec%szCounter.deccCs|jS)N)r)r
rrr�get'szCounter.getN)�__name__�
__module__�__qualname__rrrrrrrrr src@s(eZdZdd�Zdd�ZdS)�
TestThreadcCs>tjj|d|�||_||_||_||_dS)N�name)r	�Threadr�testcase�sema�mutex�nrunning)r
rrrrrrrrr+s
			zTestThread.__init__cCs1tj�d}tr4td|j|df�n|j��|j�P|jj�trtt|jj�d�n|j	j
|jj�dk�WdQXtj|�tr�td|jd�n|j�Z|jj
�|j	j
|jj�dk�tr!td	|j|jj�f�nWdQXWdQXdS)
Ng��@ztask %s will run for %.1f usecg��.Aztasks are running�Ztask�donerz$%s is finished. %d tasks are running)�randomr�printrrrrrrr�
assertTrue�time�sleepr)r
Zdelayrrr�run2s&


%


zTestThread.runN)rrrrr&rrrrr*src@s(eZdZdd�Zdd�ZdS)�BaseTestCasecCstjj�|_dS)N)�test�supportZthreading_setup�_threads)r
rrr�setUpLszBaseTestCase.setUpcCs$tjj|j�tjj�dS)N)r(r)Zthreading_cleanupr*Z
reap_children)r
rrr�tearDownOszBaseTestCase.tearDownN)rrrr+r,rrrrr'Ksr'c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zejeed�d �d!d"��Zejeed�d#�d$d%��Zd&d'�Zejeed�d(�ejeed)�d*�d+d,���Zejejekd-�ejeed�d(�ejeed)�d*�d.d/����Zd0d1�Zd2d3�Z d4d5�Z!e"d6d7��Z#d8S)9�ThreadTestscCsfd}tjdd�}tj�}t�}g}xyt|�D]k}td|||||�}|j|�|j|jd�|j	t
jdt|���|j
�q@Wtr�td�nxt|D]l}|j�|j	|j��|j|jd�|j|jdk�|j	t
jdt|���q�WtrLtd	�n|j|j�d�dS)
N�
rrz<thread %d>z<TestThread\(.*, initial\)>z!waiting for all tasks to completerz!<TestThread\(.*, stopped -?\d+\)>zall tasks done)r	�BoundedSemaphore�RLockr�ranger�append�assertEqual�identr#�re�match�repr�startrr"�join�is_alive�assertNotEqual�assertFalser)r
ZNUMTASKSrrZ
numrunning�threads�i�trrr�test_various_opsXs.	




zThreadTests.test_various_opscs�|jtj�jdk���fdd�}tj��g�tj|f��j�|j�ddk�tj�d=dS)Ncs$�jtj�j��j�dS)N)r2r	�
currentThreadr4�setr)r r4rr�f{sz9ThreadTests.test_ident_of_no_threading_threads.<locals>.fr)	r<r	rAr4�Eventr�start_new_thread�wait�_active)r
rCr)r r4r�"test_ident_of_no_threading_threadsxs
z.ThreadTests.test_ident_of_no_threading_threadscCsftrtd�nytjd�Wn$tjk
rJtjd��YnX|j�tjd�dS)Nzwith 256kB thread stack size...iz4platform does not support changing thread stack sizer)	rr"r	�
stack_sizer�error�unittest�SkipTestr@)r
rrr�test_various_ops_small_stack�s

z(ThreadTests.test_various_ops_small_stackcCsftrtd�nytjd�Wn$tjk
rJtjd��YnX|j�tjd�dS)Nzwith 1MB thread stack size...iz4platform does not support changing thread stack sizer)	rr"r	rIrrJrKrLr@)r
rrr�test_various_ops_large_stack�s

z(ThreadTests.test_various_ops_large_stackcCs|dd�}tj�}|j�tj||f�}|j�|j|tj�|jtj|tj�tj|=dS)NcSstj�|j�dS)N)r	�current_thread�release)rrrrrC�s
z*ThreadTests.test_foreign_thread.<locals>.f)	r	�Lock�acquirerrE�assertInrGZassertIsInstanceZ_DummyThread)r
rCr�tidrrr�test_foreign_thread�s

zThreadTests.test_foreign_threadc	sLtd�}|jj}Gdd�dt��|j��}tj�}y#||j|�|�}xqgWWn�k
r�YnX|jd�y|j	|d�Wnt
k
r�YnXtj��tj��G���fdd�dtj�}|�}d|_
|j�tr#td	�ntr6td
�n||jd�|�}|j	|d�trqtd�n�j�}|j|�tr�td
�n|j|j�tr�td�n||j|j�|�}|j	|d�tr�td�n�jdd�|j|j�tr2td�n|jrH|j�ndS)N�ctypesc@seZdZdS)z<ThreadTests.test_PyThreadState_SetAsyncExc.<locals>.AsyncExcN)rrrrrrr�AsyncExc�srWzAsyncExc not raisedrcs(eZdZ���fdd�ZdS)z:ThreadTests.test_PyThreadState_SetAsyncExc.<locals>.Workercsftj�|_d|_y"x�j�tjd�qWWn%�k
rad|_�j�YnXdS)NFg�������?T)r	�	get_ident�id�finishedrBr$r%)r
)rW�worker_saw_exception�worker_startedrrr&�s	

	z>ThreadTests.test_PyThreadState_SetAsyncExc.<locals>.Worker.runN)rrrr&r)rWr[r\rr�Worker�sr]Tz    started worker threadz     trying nonsensical thread idrz,    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�timeoutr.z    all OK -- joining worker���)rZ	pythonapiZPyThreadState_SetAsyncExc�	ExceptionZ	py_objectr	rXZc_longZfailr3�UnboundLocalErrorrDr�daemonr8rr"rFr#rZrYr9)	r
rVZ
set_async_excZ	exceptionrT�resultr]r?�retr)rWr[r\r�test_PyThreadState_SetAsyncExc�s^


%
		








	z*ThreadTests.test_PyThreadState_SetAsyncExccCszdd�}tj}|t_zKtjddd��}|jtj|j�|j|tjkd�Wd|t_XdS)NcWstj��dS)N)r	�ThreadError)�argsrrr�fail_new_threadsz7ThreadTests.test_limbo_cleanup.<locals>.fail_new_thread�targetcSsdS)Nrrrrr�<lambda>
sz0ThreadTests.test_limbo_cleanup.<locals>.<lambda>z:Failed to cleanup _limbo map on failure of Thread.start().)r	�_start_new_threadr�assertRaisesrfr8r<Z_limbo)r
rhrkr?rrr�test_limbo_cleanups		zThreadTests.test_limbo_cleanupcCs6td�tdd�\}}}|j|d�dS)NrVz-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)
            �*)rrr3)r
�rc�out�errrrr�test_finalize_runnning_threads
z)ThreadTests.test_finalize_runnning_threadcCstdd�dS)Nz-caPif 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)r
rrr�test_finalize_with_trace6sz$ThreadTests.test_finalize_with_tracecCsBtdd�\}}}|j|j�d�|j|d�dS)Nz-ca�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>�)rr3�strip)r
rorprqrrr�test_join_nondaemon_on_shutdownOs
z+ThreadTests.test_join_nondaemon_on_shutdownc
Cs�tj}tj�}z�xztdd�D]i}tj|d�tjddd��}|j�|j�|�}|j	||d||f�q(WWdtj|�XdS)Nr�dg-C��6*?ricSsdS)Nrrrrrrjksz7ThreadTests.test_enumerate_after_join.<locals>.<lambda>z&#1703448 triggered after %d trials: %s)
r	�	enumerate�sys�getswitchintervalr1�setswitchintervalrr8r9�assertNotIn)r
Zenum�old_intervalr>r?�lrrr�test_enumerate_after_joincs	

	z%ThreadTests.test_enumerate_after_joincCs�Gdd�dt�}|dd�}tj|�}|jj�~|j|�ddtj|���|dd�}tj|�}|jj�~|j|�ddtj|���dS)Nc@s(eZdZdd�Zdd�ZdS)zDThreadTests.test_no_refcycle_through_target.<locals>.RunSelfFunctionc	SsH||_tjd|jd|fdi|d6�|_|jj�dS)Nrirg�kwargs�yet_another)�should_raiser	r�_run�threadr8)r
r�rrrrvs
		zMThreadTests.test_no_refcycle_through_target.<locals>.RunSelfFunction.__init__cSs|jrt�ndS)N)r��
SystemExit)r
Z	other_refr�rrrr�s	zIThreadTests.test_no_refcycle_through_target.<locals>.RunSelfFunction._runN)rrrrr�rrrr�RunSelfFunctionus	r�r�F�msgz%d references still aroundT)�object�weakref�refr�r9ZassertIsNonery�getrefcount)r
r�Z
cyclic_objectZweak_cyclic_objectZraising_cyclic_objectZweak_raising_cyclic_objectrrr�test_no_refcycle_through_targetts

z+ThreadTests.test_no_refcycle_through_targetcCshtj�}|j�|jd�|j�|jd�|j�tj�}|j�tj	�dS)NTr)
r	rZisDaemonZ	setDaemonZgetNameZsetNameZisAliverDZisSetZactiveCount)r
r?�errr�test_old_threading_api�s





z"ThreadTests.test_old_threading_apicCsKtj�}|jdt|�k�d|_|jdt|�k�dS)NrbT)r	rr<r7rbr#)r
r?rrr�test_repr_daemon�s	zThreadTests.test_repr_daemoncCsdtj�}|j|j�tjdd�}|j|j�tjdd�}|j|j�dS)NrbFT)r	rr<rbr#)r
r?rrr�test_deamon_param�szThreadTests.test_deamon_param�forkztest needs fork()cCsBd}td|�\}}}|j|d�|j|d�dS)Na�if 1:
            import _thread, threading, os, time

            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()
            if os.fork() == 0:
                assert threading.active_count() == 1, threading.active_count()
                os._exit(0)
            else:
                os.wait()
        z-crt)rr3)r
�code�_rprqrrr�test_dummy_thread_after_fork�sz(ThreadTests.test_dummy_thread_after_forkzneeds os.fork()cCs�tj�}|jtj|�tjd�x�td�D]�}tjddd��}|j�|j|j�t	j
�}|dkr�t	j|j�r�dnd�q9t	j
|d�\}}|jd|�q9WdS)Ng���ư>�ricSsdS)Nrrrrrrj�sz6ThreadTests.test_is_alive_after_fork.<locals>.<lambda>rr)ryrz�
addCleanupr{r1r	rr8r9�osr��_exitr:�waitpidr3)r
r}r>r?�pid�statusrrr�test_is_alive_after_fork�s

"z$ThreadTests.test_is_alive_after_forkcs�tj�}�j|jd��j|jtj�j��j|jtj���fdd�}tjd|�}|j�|j	�dS)NZ
MainThreadcs&�jtj�jtj�j�dS)N)r;r	�main_threadr4rOr)r
rrrC�sz'ThreadTests.test_main_thread.<locals>.fri)
r	r�r3rr4rOrXrr8r9)r
�mainrCZthr)r
r�test_main_thread�s
zThreadTests.test_main_threadztest needs os.fork()r�ztest needs os.waitpid()cCsZd}td|�\}}}|j�jdd�}|j|d�|j|d�dS)Nakif 1:
            import os, threading

            pid = os.fork()
            if pid == 0:
                main = threading.main_thread()
                print(main.name)
                print(main.ident == threading.current_thread().ident)
                print(main.ident == threading.get_ident())
            else:
                os.waitpid(pid, 0)
        z-c�
�rtzMainThread
True
True
)r�decode�replacer3)r
r�r�rprq�datarrr�test_main_thread_after_fork�s
z'ThreadTests.test_main_thread_after_forkzdue to known OS bugcCsZd}td|�\}}}|j�jdd�}|j|d�|j|d�dS)Na�if 1:
            import os, threading, sys

            def f():
                pid = os.fork()
                if pid == 0:
                    main = threading.main_thread()
                    print(main.name)
                    print(main.ident == threading.current_thread().ident)
                    print(main.ident == threading.get_ident())
                    # stdout is fully buffered because not a tty,
                    # we have to flush before exit.
                    sys.stdout.flush()
                else:
                    os.waitpid(pid, 0)

            th = threading.Thread(target=f)
            th.start()
            th.join()
        z-cr�r�rtzThread-1
True
True
)rr�r�r3)r
r�r�rprqr�rrr�/test_main_thread_after_fork_from_nonmain_thread�s
z;ThreadTests.test_main_thread_after_fork_from_nonmain_threadcs"tj��tj���j��j���fdd�}tjd|�}|j|jd�|j��j�|j|j	��|j}|j
|jdd�d��j�|j|jdd�d�|j|j	��|j�|j
|j	��|j|jdk�dS)Ncs%�j��j�tjd�dS)Ng{�G�z�?)rPrRr$r%r)�finish�startedrrrC"s

z'ThreadTests.test_tstate_lock.<locals>.frir^rF�)r�
allocate_lockrRr	rZassertIsZ_tstate_lockr8r#r:r<rP)r
rCr?Ztstate_lockr)r�r�r�test_tstate_locks$



	

zThreadTests.test_tstate_lockcs�tj��tj���j��j���fdd�}tjd|�}|j��j�|jdt|���j�d}x7t	d�D])}|t|�kr�Pnt
jd�q�W|j|t|��dS)Ncs�j��j�dS)N)rPrRr)r�r�rrrCDs
z(ThreadTests.test_repr_stopped.<locals>.frir�Zstoppedi�g{�G�z�?)rr�rRr	rr8rSr7rPr1r$r%)r
rCr?ZLOOKING_FORr>r)r�r�r�test_repr_stopped>s 




zThreadTests.test_repr_stoppedcs�x�tdd�D]�}tj|���fdd�t|�D�}x|D]}|j�qKWx|D]}|j�qfW�fdd�t|�D�}x|D]}|j�q�Wx|D]}|j�q�W|jt�j�qWdS)Nrr.cs%g|]}tjd�j��qS)ri)r	rrR)�.0r�)�bsrr�
<listcomp>\s	z;ThreadTests.test_BoundedSemaphore_limit.<locals>.<listcomp>cs%g|]}tjd�j��qS)ri)r	rrP)r�r�)r�rrr�bs	)r1r	r/r8r9rl�
ValueErrorrP)r
�limitr=r?r)r�r�test_BoundedSemaphore_limitXs



z'ThreadTests.test_BoundedSemaphore_limitcs��fdd��dd����fdd��d�_tj�}tj��zHtj��ddl}|j��xtd�D]
}��q�WWdtj|�XdS)	Ncs�S)Nr)ZframeZevent�arg)�
noop_tracerrr�rsz9ThreadTests.test_frame_tstate_tracing.<locals>.noop_tracecssx	dVqWdS)N�	generatorrrrrrr�vsz8ThreadTests.test_frame_tstate_tracing.<locals>.generatorcs+�jdkr���_nt�j�S)N)�gen�nextr)�callbackr�rrr�zsz7ThreadTests.test_frame_tstate_tracing.<locals>.callbackrr)r�ry�gettrace�settracer	�	_testcapiZcall_in_temporary_c_threadr1)r
Z	old_tracer�r(r)r�r�r�r�test_frame_tstate_tracingjs	


z%ThreadTests.test_frame_tstate_tracingN)$rrrr@rHrMrNrUrermrrrsrvrr�r�r�r�rK�
skipUnless�hasattrr�r�r�r�r��skipIfry�platform�platforms_to_skipr�r�r�r�rr�rrrrr-Ts6 U!
''
*-"r-c@s<eZdZdd�Zdd�Zejeed�d�ej	e
jekd�dd	���Z
ejeed�d�ej	e
jekd�d
d���Zej	e
jekd�dd
��Zejeed�d�ej	e
jekd�dd���Zejeed�d�dd��ZdS)�ThreadJoinOnShutdowncCsNd|}td|�\}}}|j�jdd�}|j|d�dS)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()
        
z-cr�r�zend of main
end of thread
)rr�r�r3)r
�scriptrorprqr�rrr�
_run_and_join�s
z"ThreadJoinOnShutdown._run_and_joincCsd}|j|�dS)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�)r
r�rrr�test_1_join_on_shutdown�s	z,ThreadJoinOnShutdown.test_1_join_on_shutdownr�zneeds os.fork()zdue to known OS bugcCsd}|j|�dS)NaGif 1:
            childpid = os.fork()
            if childpid != 0:
                os.waitpid(childpid, 0)
                sys.exit(0)

            t = threading.Thread(target=joiningfunc,
                                 args=(threading.current_thread(),))
            t.start()
            print('end of main')
            )r�)r
r�rrr�test_2_join_in_forked_process�sz2ThreadJoinOnShutdown.test_2_join_in_forked_processcCsd}|j|�dS)Na:if 1:
            main_thread = threading.current_thread()
            def worker():
                childpid = os.fork()
                if childpid != 0:
                    os.waitpid(childpid, 0)
                    sys.exit(0)

                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
r�rrr�!test_3_join_in_forked_from_thread�sz6ThreadJoinOnShutdown.test_3_join_in_forked_from_threadcCs/d}td|�\}}}|j|�dS)Na�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.'''
                while True:
                    in_f = open(os.__file__, 'rb')
                    stuff = in_f.read(200)
                    null_f = open(os.devnull, 'wb')
                    null_f.write(stuff)
                    time.sleep(random.random() / 1995)
                    null_f.close()
                    in_f.close()
                    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()
            z-c)rr<)r
r�rorprqrrr�test_4_daemon_threads�s'z*ThreadJoinOnShutdown.test_4_daemon_threadscCsqdd�}g}x=td�D]/}tjd|�}|j|�|j�qWx|D]}|j�qYWdS)NcSs<tj�}|dkr+tj|d�n
tjd�dS)Nr)r�r�r�r�)r�rrr�do_fork_and_wait
szIThreadJoinOnShutdown.test_reinit_tls_after_fork.<locals>.do_fork_and_wait�ri)r1r	rr2r8r9)r
r�r=r>r?rrr�test_reinit_tls_after_forks	

z/ThreadJoinOnShutdown.test_reinit_tls_after_forkcCs�g}xCtd�D]5}tjddd��}|j|�|j�qWtj�}|dkr�ttj	��dkr�tj
d�q�tj
d�n(tj|d�\}}|jd|�x|D]}|j
�q�WdS)Nr�ricSs
tjd�S)Ng333333�?)r$r%rrrrrj&szKThreadJoinOnShutdown.test_clear_threads_states_after_fork.<locals>.<lambda>rr)r1r	rr2r8r�r��lenry�_current_framesr�r�r3r9)r
r=r>r?r�r�r�rrr�$test_clear_threads_states_after_forks

z9ThreadJoinOnShutdown.test_clear_threads_states_after_forkN)rrrr�r�rKr�r�r�r�ryr�r�r�r�r�r�r�rrrrr��s**'+*r�c@s:eZdZdd�Zdd�Zedd��ZdS)�SubinterpThreadingTestscCs�tj�\}}|jtj|�|jtj|�d|f}tjj|�}|j|d�|jtj|d�d�dS)Na\if 1:
            import os
            import threading
            import time

            def f():
                # Sleep a bit so that the thread is still running when
                # Py_EndInterpreter is called.
                time.sleep(0.05)
                os.write(%d, b"x")
            threading.Thread(target=f).start()
            rr�x)	r��piper��closer(r)�run_in_subinterpr3�read)r
�r�wr�rdrrr�test_threads_join;s
z)SubinterpThreadingTests.test_threads_joincCs�tj�\}}|jtj|�|jtj|�d|f}tjj|�}|j|d�|jtj|d�d�dS)Naif 1:
            import os
            import threading
            import time

            class Sleeper:
                def __del__(self):
                    time.sleep(0.05)

            tls = threading.local()

            def f():
                # Sleep a bit so that the thread is still running when
                # Py_EndInterpreter is called.
                time.sleep(0.05)
                tls.x = Sleeper()
                os.write(%d, b"x")
            threading.Thread(target=f).start()
            rrr�)	r�r�r�r�r(r)r�r3r�)r
r�r�r�rdrrr�test_threads_join_2Rs
z+SubinterpThreadingTests.test_threads_join_2c
Cs[d}d|f}tjj��td|�\}}}WdQX|jd|j��dS)NaAif 1:
            import os
            import threading
            import time

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

            _testcapi.run_in_subinterp(%r)
            z-cz:Fatal Python error: Py_EndInterpreter: not the last thread)r(r)ZSuppressCrashReportrrSr�)r
Zsubinterp_coder�rorprqrrr�test_daemon_threads_fatal_errorrs
	z7SubinterpThreadingTests.test_daemon_threads_fatal_errorN)rrrr�r�rr�rrrrr�9s r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zej	e
jdkoiej
j�d�d
d��Zdd�Zdd�Zdd�ZdS)�ThreadingExceptionTestscCs-tj�}|j�|jt|j�dS)N)r	rr8rl�RuntimeError)r
r�rrr�test_start_thread_again�s
z/ThreadingExceptionTests.test_start_thread_againcCs#tj�}|jt|j�dS)N)r	rOrlr�r9)r
rOrrr�test_joining_current_thread�sz3ThreadingExceptionTests.test_joining_current_threadcCs#tj�}|jt|j�dS)N)r	rrlr�r9)r
r�rrr�test_joining_inactive_thread�sz4ThreadingExceptionTests.test_joining_inactive_threadcCs3tj�}|j�|jtt|dd�dS)NrbT)r	rr8rlr��setattr)r
r�rrr�test_daemonize_active_thread�s
z4ThreadingExceptionTests.test_daemonize_active_threadcCs#tj�}|jt|j�dS)N)r	rQrlr�rP)r
�lockrrr�test_releasing_unacquired_lock�sz6ThreadingExceptionTests.test_releasing_unacquired_lock�darwinztest macosx problemcCs�d}d}tjtjd|gdtjdtj�}|j�\}}|j�jdd�}|j|j	dd	|j��|j||�dS)
Na}if True:
            import threading

            def recurse():
                return recurse()

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

            w = threading.Thread(target=outer)
            w.start()
            w.join()
            print('end of main thread')
            zend of main thread
z-c�stdout�stderrr�r�rzUnexpected error: )
�
subprocess�Popenry�
executable�PIPEZcommunicater�r�r3�
returncode)r
r�Zexpected_output�pr�r�r�rrr�test_recursion_limit�s z,ThreadingExceptionTests.test_recursion_limitcCs~d}td|�\}}}|j|d�|j�}|jd|�|jd|�|jd|�|jd|�dS)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()
            z-crtzException in threadz"Traceback (most recent call last):�ZeroDivisionErrorzUnhandled exception)rr3r�rSr|)r
r�rorprqrrr�test_print_exception�sz,ThreadingExceptionTests.test_print_exceptioncCs~d}td|�\}}}|j|d�|j�}|jd|�|jd|�|jd|�|jd|�dS)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()
            z-crtzException in threadz"Traceback (most recent call last):r�zUnhandled exception)rr3r�rSr|)r
r�rorprqrrr�%test_print_exception_stderr_is_none_1�sz=ThreadingExceptionTests.test_print_exception_stderr_is_none_1cCsHd}td|�\}}}|j|d�|jd|j��dS)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()
            z-crtzUnhandled exception)rr3r|r�)r
r�rorprqrrr�%test_print_exception_stderr_is_none_2�sz=ThreadingExceptionTests.test_print_exception_stderr_is_none_2N)rrrr�r�r�r�r�rKr�ryr�r(r)Zpython_is_optimizedr�r�r�r�rrrrr��s! r�c@s4eZdZdd�Zdd�Zdd�ZdS)�
TimerTestscCs)tj|�g|_tj�|_dS)N)r'r+�
callback_argsr	rD�callback_event)r
rrrr+s
	zTimerTests.setUpcCs�tjd|j�}|j�|jj�|jjd�d|jd<|jj	�tjd|j�}|j�|jj�|j
t|j�d�|j
|jfiffifg�dS)Ng{�G�z�?ZblahZbarZfoo�)
r	ZTimer�
_callback_spyr8r�rFrgr2r��clearr3r�r�)r
Ztimer1Ztimer2rrr� test_init_immutable_default_argss





z+TimerTests.test_init_immutable_default_argscOs7|jj|dd�|j�f�|jj�dS)N)r�r2�copyr�rB)r
rgr�rrrr�,s&zTimerTests._callback_spyN)rrrr+r�r�rrrrr�sr�c@seZdZeej�ZdS)�	LockTestsN)rrr�staticmethodr	rQ�locktyperrrrr�0sr�c@seZdZeej�ZdS)�PyRLockTestsN)rrrr�r	Z_PyRLockr�rrrrr�3sr�zRLock not implemented in Cc@seZdZeej�ZdS)�CRLockTestsN)rrrr�r	�_CRLockr�rrrrr�6sr�c@seZdZeej�ZdS)�
EventTestsN)rrrr�r	rDZ	eventtyperrrrr�:sr�c@seZdZeej�ZdS)�ConditionAsRLockTestsN)rrrr�r	�	Conditionr�rrrrr=src@seZdZeej�ZdS)�ConditionTestsN)rrrr�r	rZcondtyperrrrrAsrc@seZdZeej�ZdS)�SemaphoreTestsN)rrrr�r	Z	Semaphore�semtyperrrrrDsrc@seZdZeej�ZdS)�BoundedSemaphoreTestsN)rrrr�r	r/rrrrrrGsrc@seZdZeej�ZdS)�BarrierTestsN)rrrr�r	ZBarrierZbarriertyperrrrrJsr�__main__)/�__doc__Ztest.supportr(rrrrZtest.script_helperrrr!r5ryrr	r$rKr�r�r�r
r�r�rrrZTestCaser'r-r�r�r�r�r�Z
RLockTestsr�r�r�r�r�rrrrrrr�rrrr�<module>sL"	
!	��A�Q�%