o
    U˟i
                     @   s   d Z ddlmZ e  ddlZej du sJ dddlZddlmZ	 ddl
Z
dd ZG dd de	jZG d	d
 d
e	jZG dd deZedkrQe	  dS dS )z=
Tests specifically for the monkey-patched threading module.
    )monkeyNz&monkey.patch_all() should not init hubc                   C   s   t   td d S )Ng?)	threadingcurrent_threadgeventsleep r   r   d/var/www/apps/myagent/mysuperagent/venv/lib/python3.10/site-packages/gevent/tests/test__threading.pyhelper   s   r	   c                   @   s.   e Zd Zdd Zdd Zeddd ZdS )	TestCleanupc                 C   s~   t tj}|t}td | t tj|d  z|  W n ty3   |j	s0t  |j	r)~Y nw | t tj| d S )Ng?   )
lenr   _activer	   r   r   assertEqualjoinAttributeErrordead)selfspawnbeforegr   r   r   _do_test   s   

zTestCleanup._do_testc                 C      |  tj d S N)r   r   r   r   r   r   r   test_cleanup_gevent.   s   zTestCleanup.test_cleanup_geventz-weakref is not cleaned up in a timely fashionc                 C   r   r   )r   r   	spawn_rawr   r   r   r   test_cleanup_raw1   s   zTestCleanup.test_cleanup_rawN)__name__
__module____qualname__r   r   	greentest
skipOnPyPyr   r   r   r   r   r
      s
    r
   c                   @   s   e Zd Zdd Zdd ZdS )TestLockThreadc                 C   s   t j|d}|  |S )Ntarget)r   Threadstart)r   functr   r   r   _spawn8   s   zTestLockThread._spawnc                    sb   t      g  fdd}t j|d}|  | dg |d    |  d S )Nc                      s(    d  ds	  dr
d S d S )NTF)appendacquirer   lockspawnedr   r   
backgroundD   s   

z:TestLockThread.test_spin_lock_switches.<locals>.backgroundr#   Tr   )r   Lockr+   r%   r&   r   r   release)r   r/   threadr   r,   r   test_spin_lock_switches=   s   
z&TestLockThread.test_spin_lock_switchesN)r   r   r   r)   r3   r   r   r   r   r"   6   s    r"   c                   @   s   e Zd Zdd ZdS )TestLockGreenletc                 C   s
   t |S r   )r   r   )r   r'   r   r   r   r)   X   s   
zTestLockGreenlet._spawnN)r   r   r   r)   r   r   r   r   r4   V   s    r4   __main__)__doc__r   r   	patch_all
gevent.hubhub_get_hubgevent.testingtestingr    r   r	   TestCaser
   r"   r4   r   mainr   r   r   r   <module>   s    # 