o
    ,wÖiî  ã                   @   s,   d Z ddl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é   )Ú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   ú^/home/ubuntu/sommelier/.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 ˆ_	ˆƒ  ˆˆdˆƒ d S )Nr   )Úsleep)Úget_hubFÚ	_shutdown)
Ú_tstate_lockÚreleaseÚgeventr   r   Úprint_exceptionÚsysÚexc_infoÚ_is_stoppedÚ_gevent_real_tstate_lock)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   Ú_patch_thread_commonr   r   r   r   r   r   Ú<module>   s   