+
    '(j*K                     &   R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^RIHt ^RIH	t	 ^RIH
t
 ^RIHt ^RIHt ^RIHt ^RIHt ]P                   '       g   Q h ! R	 R
]4      tR t ! R R]4      t]R8X  d   ]! R4      P/                  4        R# R# )z)
Testing scenarios that may have leaked.
N)TestCase)PY314)RUNNING_ON_FREETHREAD_BUILD)WIN)fails_leakcheck)ignores_leakcheck)RUNNING_ON_MANYLINUXc                   P   a  ] tR t^t o ]! 4       tR tR tR t]	R 4       t
RtV tR# )HasFinalizerTracksInstancesc                    \         P                  ! V4      V n        V P                  P	                  \        V 4      4       R # N)sysinternmsgEXTANT_INSTANCESaddid)selfr   s   &&N/home/ubuntu/cf-venv/lib/python3.14/site-packages/greenlet/tests/test_leaks.py__init__$HasFinalizerTracksInstances.__init__   s)    ::c?!!"T(+    c                N    V P                   P                  \        V 4      4       R # r   )r   remover   r   s   &r   __del__#HasFinalizerTracksInstances.__del__    s    $$RX.r   c                >    R \        V 4      V P                  3,          # )z(<HasFinalizerTracksInstances at 0x%x %r>)r   r   r   s   &r   __repr__$HasFinalizerTracksInstances.__repr__"   s!    9tHdhh=
 
 	
r   c                :    V P                   P                  4        R # r   )r   clear)clss   &r   reset!HasFinalizerTracksInstances.reset&   s    ""$r   )r   N)__name__
__module____qualname____firstlineno__setr   r   r   r   classmethodr#   __static_attributes____classdictcell____classdict__s   @r   r
   r
      s0     u,/
 % %r   r
   c                 4    \         '       d   V # \        V 4      # r   )r   r   )funcs   &r   &fails_leakcheck_except_on_free_thradedr1   +   s    "" 4  r   c                      a  ] tR t^3t o R tR t]R 4       tR tR t	R t
RR ltR tR	 t]R
 4       t]R 4       t]R 4       t^dtR t]R 4       tRR lt]R 4       t]R 4       tRtV tR# )	TestLeaksc                    Rp\         P                  ! V4      p\        P                  ! R 4      p\        ^d4       F  pVP                  ! V!   K  	  V P                  \         P                  ! V4      V4       R# )ac                  \    \         P                  ! 4       P                  P                  ! V !  # r   greenlet
getcurrentparentswitch)argss   *r   <lambda>)TestLeaks.test_arg_refs.<locals>.<lambda>:   s    (--/66==tDr   N)r5   bc)r   getrefcountr8   ranger;   assertEqual)r   r<   refcount_beforeg_s   &    r   test_arg_refsTestLeaks.test_arg_refs5   s[    //$/DFsAHHdO .@r   c                \   / pT P                  \        P                  ! V4      \        '       g   ^M^4       \        P                  ! R 4      p\        ^d4       F  pVP                  ! R/ VB  K  	  T P                  \        P                  ! V4      \        '       g	   ^4       R# ^4       R# )   c                  `    \         P                  ! 4       P                  P                  ! R/ V B # )N r7   )gkwargss   ,r   r=   +TestLeaks.test_kwarg_refs.<locals>.<lambda>D   s!    h113::AALGLr   NrL   )rC   r   rA   r   r8   rB   r;   )r   kwargsrE   rF   s   &   r   test_kwarg_refsTestLeaks.test_kwarg_refs?   s{    055!aHLNsAHHv  	055!HaHr   c                     R  p \         P                  ! V R7      pVP                  4        \        P                  ! R4       VP                  ^
4       R# )c                  2    \         P                  ! R 4       R# )MbP?N)timesleeprL   r   r   worker+TestLeaks.__recycle_threads.<locals>.workerT   s    JJur   targetrT   N)	threadingThreadstartrU   rV   join)rW   ts     r   __recycle_threadsTestLeaks.__recycle_threadsL   s7    	F+		

5	r
r   c                  a . oV3R  lp\        ^4       F<  p\        P                  ! VR7      pVP                  4        VP	                  ^
4       ?K>  	  \
        P                  ! 4        V P                  4        \
        P                  ! 4        \        P                  ! 4        \
        P                  ! 4        S F  pV P                  V! 4       4       K  	  R# )c                  x   < S P                  \        P                  ! \        P                  ! 4       4      4       R # r   )appendweakrefrefr8   r9   )ggs   r   rW   ,TestLeaks.test_threaded_leak.<locals>.worker]   s!    IIgkk("5"5"789r   rY   NrB   r[   r\   r]   r^   r8   r9   _TestLeaks__recycle_threadsgccollectassertIsNoner   rW   rF   r_   rE   rg   s   &    @r   test_threaded_leakTestLeaks.test_threaded_leak[   s    	: qA  /AGGIFF2J	 
 	 


Aac" r   c                  a . oV3R  lp\        ^4       F<  p\        P                  ! VR7      pVP                  4        VP	                  ^
4       ?K>  	  \
        P                  ! 4        V P                  4        \
        P                  ! 4        \        P                  ! 4        \
        P                  ! 4        S F  pV P                  V! 4       4       K  	  R# )c                  *  <a . ;o\         P                  ! 4       n        V3R  lp \        ^4       F'  p\         P                   ! V 4      P	                  4        K)  	  SP                  \        P                  ! \         P                  ! 4       4      4       R# )c                  P   < S P                  \        P                  ! 4       4       R # r   )rd   r8   r9   )lls   r   
additionalDTestLeaks.test_threaded_adv_leak.<locals>.worker.<locals>.additionalr   s    		(--/0r   N)r8   r9   rt   rB   r;   rd   re   rf   )ru   rF   rt   rg   s     @r   rW   0TestLeaks.test_threaded_adv_leak.<locals>.workero   sa    ,..B$$&)11X!!*-446 IIgkk("5"5"789r   rY   Nri   rn   s   &    @r   test_threaded_adv_leak TestLeaks.test_threaded_adv_leakm   s    	: qA  /AGGIFF2J	 
 	 


Aac" r   c                V   \         P                  P                  4       pV P                  V^ 4       \         P                  P	                  R4       \         P                  P                  4       pV P                  W4       V P                  \         P                  P                  ^4       R# )    TN)r8   	_greenlet&get_clocks_used_doing_optional_cleanupassertGreaterEqualenable_optional_cleanuprC   assertGreaterCLOCKS_PER_SEC)r   usedused2s   &  r   assertClocksUsedTestLeaks.assertClocksUsed   sx    !!HHJa(2248""IIK%8--<<a@r   c                  aaa	a
aaa \         P                  ! . 4      '       g   Q h\        P                  4        \        P
                  ! 4        V P                  \        P                  R R7      p\        P                  ! 4       o
\        P                  ! 4       o	. oV3R lo. oV	V
VVVV3R lp\        P                  ! VR7      pVP                  4        S
P                  ^
4       \        P
                  ! 4        V P                  \        RR7      p\        S4      ^8X  g   Q hV P                  S^ ,          P                  4       SR S	P!                  4        VP#                  ^
4       ?V P%                  4        V P                  \        RR7      pV P                  \        P                  R R7      pV P'                  Wv4       S'       gc   \        P(                  P+                  4       eC   V P-                  W4       S'       d)   V P-                  \        P.                  \!        4       4       M \        P(                  P+                  4       e   V P1                  4        R# R# )F)
exact_kindc                  F  < \        R 4      p \        P                  P                  R\        R4      4       S'       d5   \        P                  ! 4       P
                  P                  pV! V .4       R# \        P                  ! 4       P
                  P                  V .4       R# )zDELETING STACK OBJECTtest_leaks_keyzDELETING THREAD STATEN)r
   r8   r|   set_thread_localr9   r:   r;   )jdsexplicit_reference_to_switchs     r   background_greenlet6TestLeaks._check_issue251.<locals>.background_greenlet   sv    ,-DEB// +,CDF
 ,'')00772$##%,,33RD9r   c                  V  < \         P                   ! S4      p SP                  \        P                  ! V P                  4      4       SP                  V 4       V P                  4        ? SP                  4        SP                  ^
4       S'       d   \         P                  ! 4        R# R# )
   N)	r8   rd   re   rf   r:   r;   r)   waitr9   )gletbackground_glet_killedbackground_glet_runningr   background_greenletsbg_main_wrefsmanually_collect_backgrounds    r   background_thread4TestLeaks._check_issue251.<locals>.background_thread   sy    $$%89D  T[[!9: ''-KKM#'')"''+
 +##% +r   rY   T:NNNN)rk   
is_trackedr
   r#   r8   r9   count_objectsr[   Eventr\   r]   r   listlenassertFalsedeadr)   r^   wait_for_pending_cleanupsassertLessEqualr|   r}   rC   r   r   )r   r   r   greenlets_beforer   r_   lists_beforelists_aftergreenlets_afterr   r   r   r   r   s   &ff      @@@@@r   _check_issue251TestLeaks._check_issue251   s    }}R    #))+--h.?.?E-R"+//"3!*!2!	: 	& 	&$ $56		$$R())$4)@'(A----a0556 !#""$ 	
r
 	&&((($(?,,X->->5,Q
 	[7 ,!!HHJV_?*   !<!M!MsuU DDFR!!# Sr   c                &    V P                  4        R # r   r   r   s   &r   -test_issue251_killing_cross_thread_leaks_list7TestLeaks.test_issue251_killing_cross_thread_leaks_list  s    r   c                    \         P                  P                  R 4        V P                  4        \         P                  P                  R4       R#   \         P                  P                  R4       i ; i)FTN)r8   r|   r   r   r   s   &r   #test_issue251_with_cleanup_disabled-TestLeaks.test_issue251_with_cleanup_disabled  sP    2259	=  "66t<H66t<s   A !A3c                *    V P                  R R7       R# )Fr   Nr   r   s   &r   4test_issue251_issue252_need_to_collect_in_background>TestLeaks.test_issue251_issue252_need_to_collect_in_background  s    & 	?r   c                    R V n         \        P                  P                  R4        V P	                  RR7       \        P                  P                  R 4       R#   \        P                  P                  R 4       i ; i)TFr   N)expect_greenlet_leakr8   r|   r   r   r   s   &r   Etest_issue251_issue252_need_to_collect_in_background_cleanup_disabledOTestLeaks.test_issue251_issue252_need_to_collect_in_background_cleanup_disabled*  s]    $(!2259	=  U C66t<H66t<s   A !A<c                ,    V P                  R RR7       R# )FT)r   r   Nr   r   s   &r   9test_issue251_issue252_explicit_reference_not_collectableCTestLeaks.test_issue251_issue252_explicit_reference_not_collectable3  s    (-)- 	 	/r   c                    \         P                  ^ ,          ^8  g   Q h\        '       d   V P                  R4       R# R# )r{   z!Slow and not worth repeating hereN)r   version_infor   skipTestr   s   &r   _only_test_some_versions"TestLeaks._only_test_some_versions;  s5     "a'''MM=>  r   c                r  aa V P                  4        R  oRoVV3R lp\        ^4       F
  pV! 4        K  	  V P                  4       p\        V P                  4       FD  p\	        W0P                  4       4      pV! 4        V P                  4       pWS8:  g   K;  V^8  g   KD   M	  V P                  XV4       R# )c                      ^# )   rL   rL   r   r   f:TestLeaks.test_untracked_memory_doesnt_increase.<locals>.fM  s    r   '  c                  t   < \        S4       F'  p \        P                  ! S4      P                  4        K)  	  R # r   )rB   r8   r;   )rF   ITERr   s    r   run_it?TestLeaks.test_untracked_memory_doesnt_increase.<locals>.run_itQ  s(    4[!!!$++- !r   N)r   rB   get_process_ussUNTRACK_ATTEMPTSmaxr   )r   r   rF   
uss_beforecount	uss_afterr   r   s   &     @@r   %test_untracked_memory_doesnt_increase/TestLeaks.test_untracked_memory_doesnt_increaseF  s     	%%'	 	.
 qAH  ))+
4001EZ)=)=)?@JH,,.I&519 2 	Y
3r   c                  aa	a
aaa V P                  4        V P                  4        ^ .o	V	3R loRo
V
V3R loV o ! VVV3R lR4      pR;r4\        V P                  4       EF7  p^ S	^ &   V! 4       p\        P
                  ! VR7      pVP                  4        VP                  ^4       V P                  VP                  4       4       Vf   VP                  p\        W6P                  4      pS'       dG   V P                  VP                  R	4       V P                  S	^ ,          S
VP                  ,          4       ??S'       g   V P                  S	^ ,          ^ 4       S'       d   V P                  4        V P                  4       pWC8:  g   EK.  V^8  g   EK8   M	  V P                  4        V P                  4       p\         '       d   R
M^ pV P#                  WCV,           RX3,          4       R# )r{   c                     <  \         P                  ! 4       P                  P                  4        ^#   \         P                   d    S ^ ;;,          ^,          uu&   h i ; i)r{   )r8   r9   r:   r;   GreenletExit)
EXIT_COUNTs   r   r   3TestLeaks._check_untracked_memory_thread.<locals>.ft  sP    ##%,,335  (( 1"s	   -2 ,Ar   c                     < . p \        S4       F:  p\        P                  ! S4      pV P                  V4       VP                  4        K<  	  V # r   )rB   r8   rd   r;   )gletsrF   rE   r   r   s      r   r   8TestLeaks._check_untracked_memory_thread.<locals>.run_it}  sC    E4[ %%a(Q
 ! Lr   c                   B   <a  ] tR tRt o ^ ;ttRt^tVVV3R ltRt	V t
R# )<TestLeaks._check_untracked_memory_thread.<locals>.ThreadFunci  c                \  < SP                  4       V n        \        V P                  4       F*  pV ;P                  \        S! 4       4      ,          un        K,  	  V P                   F  pSP                  R \        V4      4       K   	  S'       d   RV n        SP                  4       V n        R# )zsuspended activeNrL   )	r   r   rB   r   r   tupleassertInstrr   )r   rF   rE   deallocate_in_threadr   tests   &  r   __call__ETestLeaks._check_untracked_memory_thread.<locals>.ThreadFunc.__call__  sy    "&"6"6"8tyy)AJJ%/1J * AMM"4c!f= $ (!#DJ!%!5!5!7r   )r   r   r   NrL   )r%   r&   r'   r(   r   r   r   r   r   r+   r,   )r.   r   r   r   s   @r   
ThreadFuncr     s#     %&&JED8 8r   r   NrY   zafter attempts %drL   i   )r   r   rB   r   r[   r\   r]   r^   r   is_aliver   r   rC   r   r   r   r   r   )r   r   r   r   r   r   thread_funcr_   	tolerancer   r   r   r   r   s   &f       @@@@@r   _check_untracked_memory_thread(TestLeaks._check_untracked_memory_threadh  s   %%' 	S
	 
	 	8 	8$ "&%
4001EJqM$,K  4AGGIFF2JQZZ\*!(33
Z)?)?@J#  !2!2B7  A{7G7G0GH'  A2#..0,,.I&5195 28 	&&(((*	 #&#J1	YY(>0E8;	=r   c                *    V P                  R R7       R# )Tr   N)r   r   s   &r   Itest_untracked_memory_doesnt_increase_unfinished_thread_dealloc_in_threadSTestLeaks.test_untracked_memory_doesnt_increase_unfinished_thread_dealloc_in_thread  s     	+++Fr   c                    \         '       d*   \        '       d   \        '       d   V P                  R 4       V P	                  RR7       R# )z6Windows 3.14t appears to leak. No other platform does.Fr   N)r   r   r   r   r   r   s   &r   Gtest_untracked_memory_doesnt_increase_unfinished_thread_dealloc_in_mainQTestLeaks.test_untracked_memory_doesnt_increase_unfinished_thread_dealloc_in_main  s1     3..55MMRS+++Gr   )r   N)TF)T)r%   r&   r'   r(   rG   rP   staticmethodrj   ro   rx   r   r   r   r   r1   r   r   r   r   r   r   r   r   r   r   r+   r,   r-   s   @r   r3   r3   3   s     A
I  #$#.A|$|= ,@ ,@( ,= ,= ,/ ,/
 	? 4 4>\=| G G H Hr   r3   __main__unittest)__doc__r   rk   rU   re   r[   r8    r   r   r   r   	leakcheckr   r   r   GREENLET_USE_GCobjectr
   r1   r3   r%   
__import__mainrL   r   r   <module>r      s     	       )  & ( +
  %& % !hH hHT zz! r   