K idZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m Z m Z ddlmZdZej"dZeGdde j&Zy) aoTest script to find circular references. Circular references are not leaks per se, because they will eventually be GC'd. However, on CPython, they prevent the reference-counting fast path from being used and instead rely on the slower full GC. This increases memory footprint and CPU overhead, so we try to eliminate circular references created by normal operation. N)webgen httpclient)skipNotCPythoncfdggtttt|t|S)aFind circular references in a list of objects. The garbage list contains objects that participate in a cycle, but also the larger set of objects kept alive by that cycle. This function finds subsets of those objects that make up the cycle(s). c|D]}t|}|vr| vr|vr7j|d}|j|j|Sj|j|t j |j j| j|yN)idindexappendaddgc get_referentspopremove) levelitemitem_id candidatefound garbage_idsinnerstack stack_ids visited_idss b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/tornado/test/circlerefs_test.pyrz'find_circular_references..inner"s %DhGk)+%)#!%++d"3"56   & Y' LL  MM' " """4( ) IIK   W % OOG $# %)setmapr )garbagerrrrrrs @@@@@@rfind_circular_referencesr!sD%%("$E EIc"g&'K%K 'N Lrc#FKtjtjtjtjtj zd t j}tj}|t_ tj|t_ tjdd}gtjddt|dk(r+ tjdtjyt|D]}|jd|D]}|jdt|!|D]m}t!|t"j$s|jd|j&|jdt|t)j*|o~t-|j/#|t_ wxYw#tjdtjwxYww)zERaise AssertionError if the wrapped code creates garbage with cycles.Nrz! ========== Circular ==========z z Locals: z Traceback: )rdisablecollect set_debug DEBUG_STATS DEBUG_SAVEALLioStringIOsysstderrr lenenabler!writerepr isinstancetypes FrameTypef_locals traceback print_stackAssertionErrorgetvalue)f old_stderrr circularrs rassert_no_cycle_garbager;@sJJLJJLLL""2"223  KKMZZ   $ JJL#CJ**Q- 1 w<1   Q 19 0H GG: ;  /&d -. /  0dEOO4GGj89GGmDJ<89))$/  0  0 QZZ\**#$CJ& Q sDA!H!$/G3G#(?G3(*H!A"G35A.G3# G00G33+HH!c6eZdZdZdZdZdZdZdZdZ y) CircleRefsTestcDGfdd|jt5}t5d}d}d}||_||_||_||_~~dddddd|j dtj|j dt|j|j dt|j|jd t|jy#1swYxYw#1swYxYw) NceZdZfdZdZy))CircleRefsTest.test_known_leak..Cc>||_d|_d|_d|_yr )nameabc)selfrBCs r__init__z2CircleRefsTest.test_known_leak..C.__init__ms  -1-1-1rc d|jS)Nzname=)rBrFs r__repr__z2CircleRefsTest.test_known_leak..C.__repr__sstyyk**rN)__name__ __module__ __qualname__rHrK)rGsrrGr@ls  2  +rrGrCrDrECircularz name=az name=bz name=c) assertRaisesr6r;rDrErCassertInstr exception assertNotIn)rFcmrCrDrErGs @rtest_known_leakzCircleRefsTest.test_known_leakjs + +  ~ . "(* cFcFcFq   j#bll"34 lC $56 lC $56 s2<<'89'    s" D7D %D D DDcKtjd|fg}tjj \}}tj j |}|j|tj}t5|jd|dd{ddd|j|j|jy7=#1swY.Handlerc&|jdyNok )r.rJs rgetz5CircleRefsTest.test_sync_handler..Handler.gets 6"rNrLrMrNrqrrHandlerrms #rrtrRequestHandlerasynciorunrjrFrts rtest_sync_handlerz CircleRefsTest.test_sync_handlers- #c(( #  D$$W-.rc~Gddtj}tj|j |y)NceZdZdZy)=CircleRefsTest.test_finish_exception_handler..Handlerc,tjdro)rFinishrJs rrqzACircleRefsTest.test_finish_exception_handler..Handler.getsjj((rNrrrsrrrtr}s )rrtrurys rtest_finish_exception_handlerz,CircleRefsTest.test_finish_exception_handlers- )c(( )  D$$W-.rc~Gddtj}tj|j |y)Nc0eZdZejdZy)1CircleRefsTest.test_coro_handler..Handlerc3\Ktjd|jdywNg{Gz?rprwsleepr.rJs rrqz5CircleRefsTest.test_coro_handler..Handler.gets!mmD)) 6"s*,N)rLrMrNr coroutinerqrsrrrtrs ]] # #rrtrurys rtest_coro_handlerz CircleRefsTest.test_coro_handlers- #c(( #  D$$W-.rc~Gddtj}tj|j |y)NceZdZdZy)2CircleRefsTest.test_async_handler..HandlerclKtjdd{|jdy7wrrrJs rrqz6CircleRefsTest.test_async_handler..Handler.gets)mmD))) 6"*s 424Nrrrsrrrtrs #rrtrurys rtest_async_handlerz!CircleRefsTest.test_async_handlers- #c(( #  D$$W-.rcddl}|jjd5Gfdd}|fd}t5t j |ddddddy#1swYxYw#1swYyxYw)NrcLeZdZWZej j dZy)4CircleRefsTest.test_run_on_executor..Factorycyr rsrJs rrxz8CircleRefsTest.test_run_on_executor..Factory.runsrN)rLrMrNexecutorrZ concurrentrun_on_executorrx) thread_poolsrFactoryrs&&##33 4 rrcbKtdD]}jd{y7w)N)rangerx)ifactorys rmainz1CircleRefsTest.test_run_on_executor..mains,q(A!++-''('s "/-/)concurrent.futuresfuturesThreadPoolExecutorr;rwrx)rFrrrrrs @@rtest_run_on_executorz#CircleRefsTest.test_run_on_executors{ "    2 21 5 $  iG ( )* $ DF# $! $ $  $ $! $ $s##A=A1 A=1A: 6A==BN) rLrMrNrVrjrzrrrrrsrrr=r=hs& :D,////$rr=)__doc__rw contextlibrr(r*r4r1typingunittestrZrrrtornado.test.utilrr!contextmanagerr;TestCaser=rsrrrsx  ((,$N ##Np$X&&p$p$r