
    <|h                         d dl mZ d dlZd dlZd dlmZ  G d dej                        Zedk(  r ej                          yy)    )contextmanagerN)ignores_leakcheckc                   R    e Zd Zd Zed        Zed        Zed        Z	ed        Z
y)TestJoinc                    t        j                         j                         }| j                  |       | j	                  t        j                         j
                         t        j                         j                         }| j                  |       t        j                  d       t        j                         j                         }| j                  |       y )Ng{Gz?)geventget_hubjoin
assertTrueassertFalsedeadsleep)selfress     Z/var/www/html/test/engine/venv/lib/python3.12/site-packages/gevent/tests/test__hub_join.pytest_join_many_timeszTestJoin.test_join_many_times
   s    nn##%)../nn##% 	Tnn##%    c                  r    dd l } t        d      D ]%  }| j                         s	 | j                         r' y )Nr      )gcrangecollect)r   _s     r   __cleanzTestJoin.__clean   s/    q 	A**, **,	r   c              #      K   ddl m} | j                  } |        t         |             }d  t         |             }||kD  r|dz  }| j	                  ||       y w)Nr   )get_reachable_greenlets   )gevent._greenlet_primitivesr   _TestJoin__cleanlenassertEqual)r   r   cleancount_beforecount_afters        r   assert_no_greenlet_growthz"TestJoin.assert_no_greenlet_growth    s\     G245134% 1K 	l3s   AAc                     dd l | j                  d }fd}| j                         5  t        d      D ]
  } ||        ~~d d d        y # 1 sw Y   y xY w)Nr   c                      t        j                  d       } | j                          | j                          t        j                         }|j                          |j                  d       ~y )Nc                       yNr    r*   r   r   <lambda>zcTestJoin.test_join_in_new_thread_doesnt_leak_hub_or_greenlet.<locals>.thread_main.<locals>.<lambda>9       r   runTdestroy_loop)r   Greenletstartr
   r	   destroy)ghubs     r   thread_mainzQTestJoin.test_join_in_new_thread_doesnt_leak_hub_or_greenlet.<locals>.thread_main8   sH    I.AGGIFFH.."CHHJKKTK*r   c                 x    j                  |       }|j                          |j                                   y )N)target)Threadr2   r
   )maintr"   	threadings     r   testerzLTestJoin.test_join_in_new_thread_doesnt_leak_hub_or_greenlet.<locals>.testerA   s-       -AGGIFFHGr   
   )r<   r   r%   r   )r   r6   r=   r   r"   r<   s       @@r   3test_join_in_new_thread_doesnt_leak_hub_or_greenletz<TestJoin.test_join_in_new_thread_doesnt_leak_hub_or_greenlet2   sa     			 ++- 	2Y ${#$ 	 	 	s   AAc                     dd l }| j                  } G d d|j                        }d }t        d      D ]  } |||        ~~y )Nr   c                       e Zd ZdZd Zy)DTestJoin.test_destroy_in_main_thread_from_new_thread.<locals>.ThreadNc                     t        j                  d       }|j                          |j                          ~t        j                         }|j                          || _        y )Nc                       yr)   r*   r*   r   r   r+   zZTestJoin.test_destroy_in_main_thread_from_new_thread.<locals>.Thread.run.<locals>.<lambda>X   r,   r   r-   )r   r1   r2   r
   r	   r5   )r   r4   r5   s      r   r.   zHTestJoin.test_destroy_in_main_thread_from_new_thread.<locals>.Thread.runW   sA    OO	2	nn&
r   )__name__
__module____qualname__r5   r.   r*   r   r   r9   rB   U   s    Cr   r9   c                      |        }|j                          |j                          |j                  j                  d       d |_        ~ |        y )NTr/   )r2   r
   r5   r3   )r9   r"   r;   s      r   r=   zDTestJoin.test_destroy_in_main_thread_from_new_thread.<locals>.tester`   s<    AGGIFFHEEMMtM,AEGr   r>   )r<   r   r9   r   )r   r<   r"   r9   r=   r   s         r   +test_destroy_in_main_thread_from_new_threadz4TestJoin.test_destroy_in_main_thread_from_new_threadO   sN     			Y%% 			 r 	"A65!	" r   N)rE   rF   rG   r   staticmethodr   r   r%   r   r?   rI   r*   r   r   r   r      sW       4 4"  8 ! !r   r   __main__)

contextlibr   unittestr   gevent.testingr   TestCaser   rE   r:   r*   r   r   <module>rP      sB    %   ,ix   iX zHMMO r   