RhqddlZddlZddlZddlZddlZddlZddlZddlmZdZ dZ dZ ejddZ ddZejddZGd d Zd efd ZeZd ddZy)N)supportc\tjttjfSN)_thread_countlen threading _dangling4/usr/lib/python3.12/test/support/threading_helper.pythreading_setuprs >> S!4!45 55r cb|\}}d}tj|dD]6}ttj}t j }||ks6ydt_tjd|dd|d|d dt |D]}tjd |y) Ng?FerrorTz2threading_cleanup() failed to clean up threads in .1fz seconds before: thread count=z , dangling=z after: thread count=zDangling thread: ) rsleeping_retrylistr r rrenvironment_altered print_warningr)original_values orig_countorig_ndanglingtimeout_dangling_threadscountthreads r threading_cleanuprs!0JG  # #G5 9 3 34  J  #'G  c]"",[8HI!!&{37G3H2I KL #> 1&<=>r cBtjfd}|S)zUse this function when threads are being used. This will ensure that the threads are cleaned up even when the test fails. cNt} |t|S#t|wxYwr)rr)argskeyfuncs r decoratorzreap_threads..decorator>s) $; s # s #s $) functoolswraps)r$r%s` r reap_threadsr(:s(__T$$ r c #K|tj}tj} dt j }tj |dD]1}tjtj}||ks1yt j |z }d|z d|dd|d|d }t|#t j }tj |dD]1}tjtj}||ks1wt j |z }d|z d|dd|d|d }t|xYww) aH bpo-31234: Context manager to wait until all threads created in the with statement exit. Use _thread.count() to check if threads exited. Indirectly, wait until threads exit the internal t_bootstrap() C function of the _thread module. threading_setup() and threading_cleanup() are designed to emit a warning if a test leaves running threads in the background. This context manager is designed to cleanup threads started by the _thread.start_new_thread() which doesn't allow to wait for thread exit, whereas thread.Thread has a join() method. NFrz!wait_threads() failed to cleanup z threads after rz seconds (count: z , old count: )) r SHORT_TIMEOUTrrtime monotonicr gc_collectAssertionError)r old_count start_timerrdtmsgs r wait_threads_exitr4Hsk'' I& ^^% ''u= &A    NN$E ! & !J.B6uy7H6IJ$$&s8,#WM)A?C!% %^^% ''u= &A    NN$E ! & !J.B6uy7H6IJ$$&s8,#WM)A?C!% %s)'ECAE 8EAE8EEc|tj}|j||jrd|dd}t |y)zcJoin a thread. Raise an AssertionError if the thread is still alive after timeout seconds. Nzfailed to join the thread in rz seconds)rr+joinis_aliver/)rrr3s r join_threadr8ksJ'' KK -gc](CS!!r c #8K ddl}t|}g} |D]#}|j|j |% d |r|tj}tddD]}|dz }|D]2}|jt|tjz d4|Dcgc]}|js|}}|sn,t j sttdt||fz|Dcgc]}|js|}}|r8||jt j"t%dt|zy#t$rd}Y^wxYw#t j r"tdt|t|fzxYwcc}wcc}w#|Dcgc]}|js|ncc}w}}|r8||jt j"t%dt|zwxYw# |r|tj}tddD]}|dz }|D]2}|jt|tjz d4|Dcgc]}|js|ncc}w}}|sn,t j sztdt||fz|Dcgc]}|js|ncc}w}}|r8||jt j"t%dt|zw#|Dcgc]}|js|ncc}w}}|r8||jt j"t%dt|zwxYwxYww) Nrz/Can't start %d threads, only %d threads started<g{Gz?z7Unable to join %d threads during a period of %d minuteszUnable to join %d threads) faulthandler ImportErrorrstartappendrverboseprintrr,r-ranger6maxr7dump_tracebacksysstdoutr/)threadsunlockr=startedtendtimers r start_threadsrMwsZ7mGGQ  " q! "  Qnn&G B< B2  BAFF3w)994@AB&->1>>??'*-g,)@AB B#*:QQZZ\q:G:+ // ;$%@3w<%OPPC   G7|S\234 ?;':QQZZ\q::G:+ // ;$%@3w<%OPP! Qnn&G B< B2  BAFF3w)994@AB&->1>>>??'*-g,)@AB B#*:QQZZ\q::G:+ // ;$%@3w<%OPP#*:QQZZ\q::G:+ // ;$%@3w<%OPPsNE N(E*HA,F,1F"F" F,"F,=NF'F'=N E'#N&E''N*5FH"F,'N,H1G G  AHNNA,L2?J J L26L2NK0+K0/AN2N7M M ANNNc(eZdZdZdZdZdZdZy)catch_threading_exceptiona  Context manager catching threading.Thread exception using threading.excepthook. Attributes set when an exception is caught: * exc_type * exc_value * exc_traceback * thread See threading.excepthook() documentation for these attributes. These attributes are deleted at the context manager exit. Usage: with threading_helper.catch_threading_exception() as cm: # code spawning a thread which raises an exception ... # check the thread exception, use cm attributes: # exc_type, exc_value, exc_traceback, thread ... # exc_type, exc_value, exc_traceback, thread attributes of cm no longer # exists at this point # (to avoid reference cycles) cJd|_d|_d|_d|_d|_yr)exc_type exc_value exc_tracebackr _old_hookselfs r __init__z"catch_threading_exception.__init__s& ! r c|j|_|j|_|j|_|j|_yr)rQrRrSr)rVr"s r _hookzcatch_threading_exception._hooks1  !//kk r cZtj|_|jt_|Sr)r excepthookrTrYrUs r __enter__z#catch_threading_exception.__enter__s "--#zz  r c>|jt_|`|`|`|`yr)rTr r[rQrRrSr)rVexc_infos r __exit__z"catch_threading_exception.__exit__s##~~  M N   Kr N)__name__ __module__ __qualname____doc__rWrYr\r_r r r rOrOs<"  r rOreturnctjdk(rtjjStjdk(ryy)ayDetect whether Python can start new threads. Some WebAssembly platforms do not provide a working pthread implementation. Thread support is stubbed and any attempt to create a new thread fails. - wasm32-wasi does not have threading. - wasm32-emscripten can be compiled with or without pthread support (-s USE_PTHREADS / __EMSCRIPTEN_PTHREADS__). emscriptenwasiFT)rFplatform_emscripten_infopthreadsr r r _can_start_threadrks6 |||###,,,  r F)modulecvd}|rtstj|ytjt|S)zSkip tests or modules that require working threading. Can be used as a function/class decorator or to skip an entire module. zrequires threading supportN)can_start_threadunittestSkipTest skipUnless)rlr3s r requires_working_threadingrrs; 'C ##C( ( ""#3S99r r)r contextlibr&rFr r,rotestrrrr(contextmanagerr4r8rMrOboolrkrnrrr r r rws  6><  &&D " 'Q'QT66r4&%&). :r