Your IP : 216.73.216.213


Current Path : /opt/alt/python33/lib64/python3.3/test/__pycache__/
Upload File :
Current File : //opt/alt/python33/lib64/python3.3/test/__pycache__/test_threading.cpython-33.pyo

�
��fy�c
@s�dZddlZddlmZmZmZmZddlmZddl	Z	ddl
Z
ddlZed�Zed�Z
ddlZddlZddlZddlZddlmZmZddlZyddlZWnek
r�eZYnXddlmZGd	d
�d
e�ZGdd�de
j�ZGd
d�dej�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd�dej"�Z"Gdd�dej#�Z$ej%e
j&ekd�Gdd�dej#��Z'Gdd�dej(�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.d*kr�ej/�ndS(+u!
Tests for the threading module.
iN(uverboseustrip_python_stderru
import_moduleucpython_only(uassert_python_oku_threadu	threading(uassert_python_okuassert_python_failure(u
lock_testscBsD|EeZdZdd�Zdd�Zdd�Zdd�Zd	S(
uCountercCs
d|_dS(Ni(uvalue(uself((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu__init__suCounter.__init__cCs|jd7_dS(Ni(uvalue(uself((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuincsuCounter.inccCs|jd8_dS(Ni(uvalue(uself((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyudec!suCounter.deccCs|jS(N(uvalue(uself((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuget#suCounter.getN(u__name__u
__module__u__qualname__u__init__uincudecuget(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuCountersuCountercBs,|EeZdZdd�Zdd�ZdS(u
TestThreadcCs>tjj|d|�||_||_||_||_dS(Nuname(u	threadinguThreadu__init__utestcaseusemaumutexunrunning(uselfunameutestcaseusemaumutexunrunning((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu__init__'s
			uTestThread.__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��@utask %s will run for %.1f usecg��.Autasks are runningiutaskudoneiu$%s is finished. %d tasks are running(urandomuverboseuprintunameusemaumutexunrunninguincugetutestcaseu
assertTrueutimeusleepudec(uselfudelay((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyurun.s&


%


uTestThread.runN(u__name__u
__module__u__qualname__u__init__urun(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu
TestThread&su
TestThreadcBs,|EeZdZdd�Zdd�ZdS(uBaseTestCasecCstjj�|_dS(N(utestusupportuthreading_setupu_threads(uself((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyusetUpHsuBaseTestCase.setUpcCs$tjj|j�tjj�dS(N(utestusupportuthreading_cleanupu_threadsu
reap_children(uself((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutearDownKsuBaseTestCase.tearDownN(u__name__u
__module__u__qualname__usetUputearDown(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuBaseTestCaseGsuBaseTestCasecBs"|EeZdZdd�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'�Zd(S()uThreadTestscCsid}tjdd�}tj�}t�}g}xyt|�D]k}td|||||�}|j|�|j|jd�|j
tjdt
|���|j�q@Wtr�td�nxw|D]o}|j|�|j
|j��|j|jd�|j|jdk�|j
tjdt
|���q�WtrOtd	�n|j|j�d�dS(
Ni
uvalueiu<thread %d>u<TestThread\(.*, initial\)>u!waiting for all tasks to completeiu!<TestThread\(.*, stopped -?\d+\)>uall tasks done(u	threadinguBoundedSemaphoreuRLockuCounterurangeu
TestThreaduappenduassertEqualuidentuNoneu
assertTrueureumatchureprustartuverboseuprintujoinuis_aliveuassertNotEqualuassertFalseuget(uselfuNUMTASKSusemaumutexu
numrunninguthreadsuiut((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_various_opsTs.	




uThreadTests.test_various_opscs�|jtj�jdk���fdd�}tj��g�tj|f��j�|j�ddk�tj	�d=dS(Ncs$�jtj�j��j�dS(N(uappendu	threadingu
currentThreaduidentuset((udoneuident(u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyufwsu9ThreadTests.test_ident_of_no_threading_threads.<locals>.fi(
uassertFalseu	threadingu
currentThreaduidentuNoneuEventu_threadustart_new_threaduwaitu_active(uselfuf((udoneuidentu8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu"test_ident_of_no_threading_threadsts
u.ThreadTests.test_ident_of_no_threading_threadscCsftrtd�nytjd�Wn$tjk
rJtjd��YnX|j�tjd�dS(Nuwith 256kB thread stack size...iu4platform does not support changing thread stack sizei(	uverboseuprintu	threadingu
stack_sizeu_threaduerroruunittestuSkipTestutest_various_ops(uself((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_various_ops_small_stack�s

u(ThreadTests.test_various_ops_small_stackcCsftrtd�nytjd�Wn$tjk
rJtjd��YnX|j�tjd�dS(Nuwith 1MB thread stack size...iu4platform does not support changing thread stack sizei(	uverboseuprintu	threadingu
stack_sizeu_threaduerroruunittestuSkipTestutest_various_ops(uself((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_various_ops_large_stack�s

u(ThreadTests.test_various_ops_large_stackcCs|dd�}tj�}|j�tj||f�}|j�|j|tj�|jtj|tj�tj|=dS(NcSstj�|j�dS(N(u	threadingucurrent_threadurelease(umutex((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuf�s
u*ThreadTests.test_foreign_thread.<locals>.f(	u	threadinguLockuacquireu_threadustart_new_threaduassertInu_activeuassertIsInstanceu_DummyThread(uselfufumutexutid((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_foreign_thread�s

uThreadTests.test_foreign_threadc	sKtd�}|jj}Gdd�dt��|j��}tj�}y"||j|�|�}xqgWn�k
rYnX|jd�y|j	|d�Wnt
k
r�YnXtj��tj��G���fdd�dtj�}|�}d|_|j�tr"td�ntr5td	�n||jd�|�}|j	|d
�trptd�n�j�}|j|�tr�td�n|j|j�tr�td
�n||j|j�|�}|j	|d�tr�td�n�jdd�|j|j�tr1td�n|jrG|j�ndS(NuctypescBs|EeZdZdS(u<ThreadTests.test_PyThreadState_SetAsyncExc.<locals>.AsyncExcN(u__name__u
__module__u__qualname__(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuAsyncExc�suAsyncExcuAsyncExc not raisedics,|EeZdZ���fdd�ZdS(u:ThreadTests.test_PyThreadState_SetAsyncExc.<locals>.Workercsetj�|_d|_y!x�j�tjd�qWn%�k
r`d|_�j�YnXdS(Ng�������?FT(	u	threadingu	get_identuiduFalseufinishedusetutimeusleepuTrue(uself(uAsyncExcuworker_saw_exceptionuworker_started(u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyurun�s	

	u>ThreadTests.test_PyThreadState_SetAsyncExc.<locals>.Worker.runN(u__name__u
__module__u__qualname__urun(u
__locals__(uAsyncExcuworker_saw_exceptionuworker_started(u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuWorker�suWorkeru    started worker threadu     trying nonsensical thread idiu,    waiting for worker thread to get startedu"    verifying worker hasn't exitedu2    attempting to raise asynch exception in workeru5    waiting for worker to say it caught the exceptionutimeouti
u    all OK -- joining workerTi����(u
import_moduleu	pythonapiuPyThreadState_SetAsyncExcu	Exceptionu	py_objectu	threadingu	get_identuc_longufailuassertEqualuUnboundLocalErroruEventuThreaduTrueudaemonustartuverboseuprintuwaitu
assertTrueufinisheduidujoin(	uselfuctypesu
set_async_excu	exceptionutiduresultuWorkeruturet((uAsyncExcuworker_saw_exceptionuworker_startedu8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_PyThreadState_SetAsyncExc�s^


%
		








	u*ThreadTests.test_PyThreadState_SetAsyncExccCszdd�}tj}|t_zKtjddd��}|jtj|j�|j|tjkd�Wd|t_XdS(NcWstj��dS(N(u	threadinguThreadError(uargs((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyufail_new_threadsu7ThreadTests.test_limbo_cleanup.<locals>.fail_new_threadutargetcSsdS(N(uNone(((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu<lambda>	su0ThreadTests.test_limbo_cleanup.<locals>.<lambda>u:Failed to cleanup _limbo map on failure of Thread.start().(u	threadingu_start_new_threaduThreaduassertRaisesuThreadErrorustartuassertFalseu_limbo(uselfufail_new_threadu_start_new_threadut((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_limbo_cleanups		uThreadTests.test_limbo_cleanupcCs6td�tdd�\}}}|j|d�dS(Nuctypesu-cuNif 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)
            i*(u
import_moduleuassert_python_failureuassertEqual(uselfurcuoutuerr((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_finalize_runnning_threads
u)ThreadTests.test_finalize_runnning_threadcCstdd�dS(Nu-cuPif 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)
            (uassert_python_ok(uself((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_finalize_with_trace2su$ThreadTests.test_finalize_with_tracecCsBtdd�\}}}|j|j�d�|j|d�dS(Nu-cu�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>s(uassert_python_okuassertEqualustrip(uselfurcuoutuerr((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_join_nondaemon_on_shutdownKs
u+ThreadTests.test_join_nondaemon_on_shutdownc
Cs�tj}tj�}z�xztdd�D]i}tj|d�tjddd��}|j�|j�|�}|j	||d||f�q(WWdtj|�XdS(Niidg-C��6*?utargetcSsdS(N(uNone(((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu<lambda>gsu7ThreadTests.test_enumerate_after_join.<locals>.<lambda>u&#1703448 triggered after %d trials: %s(
u	threadingu	enumerateusysugetswitchintervalurangeusetswitchintervaluThreadustartujoinuassertNotIn(uselfuenumuold_intervaluiutul((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_enumerate_after_join_s	

	u%ThreadTests.test_enumerate_after_joincCs�Gdd�dt�}|dd�}tj|�}|jj�~|j|�ddtj|���|dd�}tj|�}|jj�~|j|�ddtj|���dS(NcBs,|EeZdZdd�Zdd�ZdS(uDThreadTests.test_no_refcycle_through_target.<locals>.RunSelfFunctionc	SsH||_tjd|jd|fdi|d6�|_|jj�dS(Nutargetuargsukwargsuyet_another(ushould_raiseu	threadinguThreadu_runuthreadustart(uselfushould_raise((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu__init__rs
		uMThreadTests.test_no_refcycle_through_target.<locals>.RunSelfFunction.__init__cSs|jrt�ndS(N(ushould_raiseu
SystemExit(uselfu	other_refuyet_another((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu_run{s	uIThreadTests.test_no_refcycle_through_target.<locals>.RunSelfFunction._runN(u__name__u
__module__u__qualname__u__init__u_run(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuRunSelfFunctionqs	uRunSelfFunctionushould_raiseumsgu%d references still aroundFT(
uobjectuFalseuweakrefurefuthreadujoinuassertIsNoneusysugetrefcountuTrue(uselfuRunSelfFunctionu
cyclic_objectuweak_cyclic_objecturaising_cyclic_objectuweak_raising_cyclic_object((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_no_refcycle_through_targetps

u+ThreadTests.test_no_refcycle_through_targetcCshtj�}|j�|jd�|j�|jd�|j�tj�}|j	�tj
�dS(NunameT(u	threadinguThreaduisDaemonu	setDaemonuTrueugetNameusetNameuisAliveuEventuisSetuactiveCount(uselfutue((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_old_threading_api�s





u"ThreadTests.test_old_threading_apicCsKtj�}|jdt|�k�d|_|jdt|�k�dS(NudaemonT(u	threadinguThreaduassertFalseurepruTrueudaemonu
assertTrue(uselfut((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_repr_daemon�s	uThreadTests.test_repr_daemoncCsdtj�}|j|j�tjdd�}|j|j�tjdd�}|j|j�dS(NudaemonFT(u	threadinguThreaduassertFalseudaemonuFalseuTrueu
assertTrue(uselfut((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_deamon_param�suThreadTests.test_deamon_paramuforkutest needs fork()cCsBd}td|�\}}}|j|d�|j|d�dS(Nu�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()
        u-cs(uassert_python_okuassertEqual(uselfucodeu_uoutuerr((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_dummy_thread_after_fork�su(ThreadTests.test_dummy_thread_after_forkuneeds 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���ư>iutargetcSsdS(N(uNone(((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu<lambda>�su6ThreadTests.test_is_alive_after_fork.<locals>.<lambda>ii(usysugetswitchintervalu
addCleanupusetswitchintervalurangeu	threadinguThreadustartujoinuosuforku_exituis_aliveuwaitpiduassertEqual(uselfuold_intervaluiutupidustatus((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_is_alive_after_fork�s

"u$ThreadTests.test_is_alive_after_forkcs�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(Nii
cs%g|]}tjd�j��qS(utarget(u	threadinguThreaduacquire(u.0u_(ubs(u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu
<listcomp>�s	u;ThreadTests.test_BoundedSemaphore_limit.<locals>.<listcomp>cs%g|]}tjd�j��qS(utarget(u	threadinguThreadurelease(u.0u_(ubs(u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu
<listcomp>�s	(urangeu	threadinguBoundedSemaphoreustartujoinuassertRaisesu
ValueErrorurelease(uselfulimituthreadsut((ubsu8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_BoundedSemaphore_limit�s



u'ThreadTests.test_BoundedSemaphore_limitN(u__name__u
__module__u__qualname__utest_various_opsu"test_ident_of_no_threading_threadsutest_various_ops_small_stackutest_various_ops_large_stackutest_foreign_threadutest_PyThreadState_SetAsyncExcutest_limbo_cleanuputest_finalize_runnning_threadutest_finalize_with_traceutest_join_nondaemon_on_shutdownutest_enumerate_after_joinutest_no_refcycle_through_targetutest_old_threading_apiutest_repr_daemonutest_deamon_paramuunittestu
skipUnlessuhasattruosutest_dummy_thread_after_forkutest_is_alive_after_forkutest_BoundedSemaphore_limit(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuThreadTestsPs$ U!
''uThreadTestscBs�|EeZdZd Zdd�Zd	d
�Zejee	d�d�ej
ejekd
�dd���Z
ejee	d�d�ej
ejekd
�dd���Zdd�Zejee	d�d�ej
ejekd
�dd���Zejee	d�d�ej
ejekd
�dd���Zej
ejekd
�dd��Zejee	d�d�ej
ejekd
�dd���Zeej
edkd�dd���ZdS(!uThreadJoinOnShutdownufreebsd4ufreebsd5ufreebsd6unetbsd5uos2emxuhp-ux11cCsNd|}td|�\}}}|j�jdd�}|j|d�dS(Nu�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()
        
u-cu
uuend of main
end of thread
(uassert_python_okudecodeureplaceuassertEqual(uselfuscripturcuoutuerrudata((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu
_run_and_join�s
u"ThreadJoinOnShutdown._run_and_joincCsd}|j|�dS(Nu�if 1:
            import os
            t = threading.Thread(target=joiningfunc,
                                 args=(threading.current_thread(),))
            t.start()
            time.sleep(0.1)
            print('end of main')
            (u
_run_and_join(uselfuscript((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_1_join_on_shutdowns	u,ThreadJoinOnShutdown.test_1_join_on_shutdownuforkuneeds os.fork()udue to known OS bugcCsd}|j|�dS(NuGif 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')
            (u
_run_and_join(uselfuscript((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_2_join_in_forked_processsu2ThreadJoinOnShutdown.test_2_join_in_forked_processcCsd}|j|�dS(Nu: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()
            (u
_run_and_join(uselfuscript((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu!test_3_join_in_forked_from_thread$su6ThreadJoinOnShutdown.test_3_join_in_forked_from_threadcCsDtd|�\}}}|j�jdd�}|j||�dS(Nu-cu
u(uassert_python_okudecodeureplaceuassertEqual(uselfuscriptuexpected_outputurcuoutuerrudata((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuassertScriptHasOutput=su*ThreadJoinOnShutdown.assertScriptHasOutputcCsd}|j|d�dS(NuDif 1:
            import os, time, threading

            finish_join = False
            start_fork = False

            def worker():
                # Wait until this thread's lock is acquired before forking to
                # create the deadlock.
                global finish_join
                while not start_fork:
                    time.sleep(0.01)
                # LOCK HELD: Main thread holds lock across this call.
                childpid = os.fork()
                finish_join = True
                if childpid != 0:
                    # Parent process just waits for child.
                    os.waitpid(childpid, 0)
                # Child process should just return.

            w = threading.Thread(target=worker)

            # Stub out the private condition variable's lock acquire method.
            # This acquires the lock and then waits until the child has forked
            # before returning, which will release the lock soon after.  If
            # someone else tries to fix this test case by acquiring this lock
            # before forking instead of resetting it, the test case will
            # deadlock when it shouldn't.
            condition = w._block
            orig_acquire = condition.acquire
            call_count_lock = threading.Lock()
            call_count = 0
            def my_acquire():
                global call_count
                global start_fork
                orig_acquire()  # LOCK ACQUIRED HERE
                start_fork = True
                if call_count == 0:
                    while not finish_join:
                        time.sleep(0.01)  # WORKER THREAD FORKS HERE
                with call_count_lock:
                    call_count += 1
            condition.acquire = my_acquire

            w.start()
            w.join()
            print('end of main')
            uend of main
(uassertScriptHasOutput(uselfuscript((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu+test_4_joining_across_fork_in_worker_threadBsFu@ThreadJoinOnShutdown.test_4_joining_across_fork_in_worker_threadcCs d}d}|j||�dS(Nuif True:
            import os, time, threading

            start_fork = False

            def worker():
                # Wait until the main thread has attempted to join this thread
                # before continuing.
                while not start_fork:
                    time.sleep(0.01)
                childpid = os.fork()
                if childpid != 0:
                    # Parent process just waits for child.
                    (cpid, rc) = os.waitpid(childpid, 0)
                    assert cpid == childpid
                    assert rc == 0
                    print('end of worker thread')
                else:
                    # Child process should just return.
                    pass

            w = threading.Thread(target=worker)

            # Stub out the private condition variable's _release_save method.
            # This releases the condition's lock and flips the global that
            # causes the worker to fork.  At this point, the problematic waiter
            # lock has been acquired once by the waiter and has been put onto
            # the waiters list.
            condition = w._block
            orig_release_save = condition._release_save
            def my_release_save():
                global start_fork
                orig_release_save()
                # Waiter lock held here, condition lock released.
                start_fork = True
            condition._release_save = my_release_save

            w.start()
            w.join()
            print('end of main thread')
            u(end of worker thread
end of main thread
(uassertScriptHasOutput(uselfuscriptuoutput((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu(test_5_clear_waiter_locks_to_avoid_crash�s6u=ThreadJoinOnShutdown.test_5_clear_waiter_locks_to_avoid_crashcCs/d}td|�\}}}|j|�dS(Nu�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()
            u-c(uassert_python_okuassertFalse(uselfuscripturcuoutuerr((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_6_daemon_threads�s'u*ThreadJoinOnShutdown.test_6_daemon_threadscCsqdd�}g}x=td�D]/}tjd|�}|j|�|j�qWx|D]}|j�qYWdS(NcSs<tj�}|dkr+tj|d�n
tjd�dS(Ni(uosuforkuwaitpidu_exit(upid((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyudo_fork_and_wait�suIThreadJoinOnShutdown.test_reinit_tls_after_fork.<locals>.do_fork_and_waitiutarget(urangeu	threadinguThreaduappendustartujoin(uselfudo_fork_and_waituthreadsuiut((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_reinit_tls_after_fork�s	

u/ThreadJoinOnShutdown.test_reinit_tls_after_forkuneed _testcapi modulecs��fdd��dd����fdd��d�_tj�}tj��z<tj��tj��xtd�D]
}��qWWdtj|�XdS(Ncs�S(N((uframeueventuarg(u
noop_trace(u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu
noop_tracesuBThreadJoinOnShutdown.test_frame_tstate_tracing.<locals>.noop_tracecssxdVqdS(Nu
genereator((((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu	generatorsuAThreadJoinOnShutdown.test_frame_tstate_tracing.<locals>.generatorcs+�jdkr���_nt�j�S(N(ugenuNoneunext((ucallbacku	generator(u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyucallbacksu@ThreadJoinOnShutdown.test_frame_tstate_tracing.<locals>.callbacki(	uNoneugenusysugettraceusettraceu	threadingu	_testcapiucall_in_temporary_c_threadurange(uselfu	old_traceutest((ucallbacku	generatoru
noop_traceu8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_frame_tstate_tracings		


u.ThreadJoinOnShutdown.test_frame_tstate_tracingN(ufreebsd4ufreebsd5ufreebsd6unetbsd5uos2emxuhp-ux11(u__name__u
__module__u__qualname__uplatforms_to_skipu
_run_and_joinutest_1_join_on_shutdownuunittestu
skipUnlessuhasattruosuskipIfusysuplatformutest_2_join_in_forked_processu!test_3_join_in_forked_from_threaduassertScriptHasOutputu+test_4_joining_across_fork_in_worker_threadu(test_5_clear_waiter_locks_to_avoid_crashutest_6_daemon_threadsutest_reinit_tls_after_forkucpython_onlyu	_testcapiuNoneutest_frame_tstate_tracing(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuThreadJoinOnShutdown�s$***H*9'+*uThreadJoinOnShutdowncBs�|EeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zej	e
jdkomej
j�d�d
d��ZdS(uThreadingExceptionTestscCs-tj�}|j�|jt|j�dS(N(u	threadinguThreadustartuassertRaisesuRuntimeError(uselfuthread((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_start_thread_again4s
u/ThreadingExceptionTests.test_start_thread_againcCs#tj�}|jt|j�dS(N(u	threadingucurrent_threaduassertRaisesuRuntimeErrorujoin(uselfucurrent_thread((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_joining_current_thread9su3ThreadingExceptionTests.test_joining_current_threadcCs#tj�}|jt|j�dS(N(u	threadinguThreaduassertRaisesuRuntimeErrorujoin(uselfuthread((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_joining_inactive_thread=su4ThreadingExceptionTests.test_joining_inactive_threadcCs3tj�}|j�|jtt|dd�dS(NudaemonT(u	threadinguThreadustartuassertRaisesuRuntimeErrorusetattruTrue(uselfuthread((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_daemonize_active_threadAs
u4ThreadingExceptionTests.test_daemonize_active_threadcCs#tj�}|jt|j�dS(N(u	threadinguLockuassertRaisesuRuntimeErrorurelease(uselfulock((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_releasing_unacquired_lockFsu6ThreadingExceptionTests.test_releasing_unacquired_lockudarwinutest macosx problemcCs�d}d}tjtjd|gdtjdtj�}|j�\}}|j�jdd�}|j|j	dd	|j��|j||�dS(
Nu}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')
            uend of main thread
u-custdoutustderru
uiuUnexpected error: (
u
subprocessuPopenusysu
executableuPIPEucommunicateudecodeureplaceuassertEqualu
returncode(uselfuscriptuexpected_outputupustdoutustderrudata((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyutest_recursion_limitJs u,ThreadingExceptionTests.test_recursion_limitN(u__name__u
__module__u__qualname__utest_start_thread_againutest_joining_current_threadutest_joining_inactive_threadutest_daemonize_active_threadutest_releasing_unacquired_lockuunittestu
skipUnlessusysuplatformutestusupportupython_is_optimizedutest_recursion_limit(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuThreadingExceptionTests1s!uThreadingExceptionTestscBs8|EeZdZdd�Zdd�Zdd�ZdS(u
TimerTestscCs)tj|�g|_tj�|_dS(N(uBaseTestCaseusetUpu
callback_argsu	threadinguEventucallback_event(uself((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyusetUpms
	uTimerTests.setUpcCs�tjd|j�}|j�|jj�|jjd�d|jd<|jj	�tjd|j�}|j�|jj�|j
t|j�d�|j
|jfiffifg�dS(Ng{�G�z�?ublahubarufooi(
u	threadinguTimeru
_callback_spyustartucallback_eventuwaituargsuappendukwargsuclearuassertEqualulenu
callback_args(uselfutimer1utimer2((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu test_init_immutable_default_argsrs





u+TimerTests.test_init_immutable_default_argscOs7|jj|dd�|j�f�|jj�dS(N(u
callback_argsuappenducopyucallback_eventuset(uselfuargsukwargs((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu
_callback_spy�s&uTimerTests._callback_spyN(u__name__u
__module__u__qualname__usetUpu test_init_immutable_default_argsu
_callback_spy(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu
TimerTestsksu
TimerTestscBs#|EeZdZeej�ZdS(u	LockTestsN(u__name__u
__module__u__qualname__ustaticmethodu	threadinguLockulocktype(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu	LockTests�su	LockTestscBs#|EeZdZeej�ZdS(uPyRLockTestsN(u__name__u
__module__u__qualname__ustaticmethodu	threadingu_PyRLockulocktype(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuPyRLockTests�suPyRLockTestsuRLock not implemented in CcBs#|EeZdZeej�ZdS(uCRLockTestsN(u__name__u
__module__u__qualname__ustaticmethodu	threadingu_CRLockulocktype(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuCRLockTests�suCRLockTestscBs#|EeZdZeej�ZdS(u
EventTestsN(u__name__u
__module__u__qualname__ustaticmethodu	threadinguEventu	eventtype(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu
EventTests�su
EventTestscBs#|EeZdZeej�ZdS(uConditionAsRLockTestsN(u__name__u
__module__u__qualname__ustaticmethodu	threadingu	Conditionulocktype(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuConditionAsRLockTests�suConditionAsRLockTestscBs#|EeZdZeej�ZdS(uConditionTestsN(u__name__u
__module__u__qualname__ustaticmethodu	threadingu	Conditionucondtype(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuConditionTests�suConditionTestscBs#|EeZdZeej�ZdS(uSemaphoreTestsN(u__name__u
__module__u__qualname__ustaticmethodu	threadingu	Semaphoreusemtype(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuSemaphoreTests�suSemaphoreTestscBs#|EeZdZeej�ZdS(uBoundedSemaphoreTestsN(u__name__u
__module__u__qualname__ustaticmethodu	threadinguBoundedSemaphoreusemtype(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuBoundedSemaphoreTests�suBoundedSemaphoreTestscBs#|EeZdZeej�ZdS(uBarrierTestsN(u__name__u
__module__u__qualname__ustaticmethodu	threadinguBarrierubarriertype(u
__locals__((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyuBarrierTests�suBarrierTestsu__main__(0u__doc__utest.supportutestuverboseustrip_python_stderru
import_moduleucpython_onlyutest.script_helperuassert_python_okurandomureusysu_threadu	threadingutimeuunittestuweakrefuosuassert_python_failureu
subprocessu	_testcapiuImportErroruNoneu
lock_testsuobjectuCounteruThreadu
TestThreaduTestCaseuBaseTestCaseuThreadTestsuThreadJoinOnShutdownuThreadingExceptionTestsu
TimerTestsu	LockTestsu
RLockTestsuPyRLockTestsuskipIfu_CRLockuCRLockTestsu
EventTestsuConditionAsRLockTestsuConditionTestsuSemaphoreTestsuBoundedSemaphoreTestsuBarrierTestsu__name__umain(((u8/opt/alt/python33/lib64/python3.3/test/test_threading.pyu<module>sP"

!	���E:%