o
    oin                     @   s8   d Z ddlZddlmZ ddlmZ G dd deZdS )z^
The implementation of thread patching for Python versions
prior to 3.13.

Internal use only.
    N)LoopExit   )BasePatcherc                   @   s   e Zd Zdd Zdd ZdS )Patcherc                 C   sB   ddl m} | j}|j D ]}|| krq| |d ||_qd S )Nr   )main_native_thread)gevent.threadingr   threading_mod_activevalues(_make_existing_non_main_thread_join_funcjoin)selfr   r   thread r   `/var/www/html/pca-backend/venv/lib/python3.10/site-packages/gevent/monkey/_patch_thread_lt313.pypatch_active_threads   s   
zPatcher.patch_active_threadsc                    s   dd l }ddlm | j| j| j|   _j_	j	d us%J 
 _j   fdd}d| d S )Nr   r   )
patch_itemc                     s   j sd S j   ddlm}  z|   W n   ddlm} | j gt R   Y d_j	_ d _	z  W n	 t
yD   Y nw d d S )Nr   )sleep)get_hubF	_shutdown)_tstate_lockreleasegeventr   r   print_exceptionsysexc_info_is_stopped_gevent_real_tstate_lockr   )r   r   	_greenletmain_threadorig_shutdownr   r   r   r   r   /   s$   


zVPatcher.patch_threading_shutdown_on_main_thread_not_already_patched.<locals>._shutdownr   )greenletapir   r   r    r!   
getcurrentr   r   r   Lockacquire)r   r"   r   r   r   r   ;patch_threading_shutdown_on_main_thread_not_already_patched   s   


"zCPatcher.patch_threading_shutdown_on_main_thread_not_already_patchedN)__name__
__module____qualname__r   r'   r   r   r   r   r      s    	r   )__doc__r   gevent.exceptionsr   _patch_thread_commonr   r   r   r   r   r   <module>   s
   