
    <|h
                     :   d Z ddlmZ  ej                          ddlZej
                  j                         J d       ddlZddlmZ	 ddl
Z
d Z G d de	j                        Z G d d	e	j                        Z G d
 de      Zedk(  r e	j"                          yy)z=
Tests specifically for the monkey-patched threading module.
    )monkeyNz&monkey.patch_all() should not init hubc                  V    t        j                          t        j                  d       y )Ng?)	threadingcurrent_threadgeventsleep     [/var/www/html/test/engine/venv/lib/python3.12/site-packages/gevent/tests/test__threading.pyhelperr      s    
LLr
   c                   H    e Zd Zd Zd Z ej                  d      d        Zy)TestCleanupc                    t        t        j                        } |t              }t	        j
                  d       | j                  t        t        j                        |dz          	 |j                          | j                  t        t        j                        |       y # t        $ r1 |j                  s!t	        j
                          |j                  s!~Y cw xY w)Ng?   )
lenr   _activer   r   r   assertEqualjoinAttributeErrordead)selfspawnbeforegs       r   _do_testzTestCleanup._do_test   s    Y&&'&MSY../!<	FFH 	Y../8  	ff ff
 	s   (B" "5CCCc                 B    | j                  t        j                         y N)r   r   r   r   s    r   test_cleanup_geventzTestCleanup.test_cleanup_gevent.   s    fll#r
   z-weakref is not cleaned up in a timely fashionc                 B    | j                  t        j                         y r   )r   r   	spawn_rawr   s    r   test_cleanup_rawzTestCleanup.test_cleanup_raw1   s    f&&'r
   N)__name__
__module____qualname__r   r   	greentest
skipOnPyPyr"   r	   r
   r   r   r      s/    92$ YIJ( K(r
   r   c                       e Zd Zd Zd Zy)TestLockThreadc                 R    t        j                  |      }|j                          |S )Ntarget)r   Threadstart)r   functs      r   _spawnzTestLockThread._spawn8   s     D)		r
   c                 4   t        j                         j                          g fd}t        j                  |      }|j	                          | j                  dg       |j                  d       j                          |j                          y )Nc                  r    j                  d        j                  d      s	  j                  d      sy y )NTF)appendacquire)lockspawneds   r   
backgroundz:TestLockThread.test_spin_lock_switches.<locals>.backgroundD   s,    NN4 ll5) ll5)r
   r+   Tr   )r   Lockr5   r-   r.   r   r   release)r   r8   threadr6   r7   s      @@r   test_spin_lock_switchesz&TestLockThread.test_spin_lock_switches=   sp     ~~	
 !!4 	4&)Ar
   N)r#   r$   r%   r1   r<   r	   r
   r   r)   r)   6   s    
r
   r)   c                       e Zd Zd Zy)TestLockGreenletc                 ,    t        j                  |      S r   )r   r   )r   r/   s     r   r1   zTestLockGreenlet._spawnX   s    ||D!!r
   N)r#   r$   r%   r1   r	   r
   r   r>   r>   V   s    "r
   r>   __main__)__doc__r   r   	patch_all
gevent.hubhub_get_hubgevent.testingtestingr&   r   r   TestCaser   r)   r>   r#   mainr	   r
   r   <module>rJ      s    +6++-  zz$ N&N N$  "  ()$$  (FY'' @"~ "
 zINN r
   