
    i                     F    d Z ddlZddlmZ ddlmZ  G d de          ZdS )z[
The implementation of thread patching for Python versions
after 3.13.

Internal use only.
    N)LoopExit   )BasePatcherc                       e Zd Zd Zd ZdS )Patcherc                    ddl m} | j        j                                        D ]}| |            k    rddlm} ddlm} dd|_	         |            }|
                     |                       d}t          |d          rd}t          |||           |j        |_        |j        t          ||          j        k    sJ |                     |d | j                  |_        d S )	Nr   )main_native_thread)_ThreadHandle)
getcurrentc                     | S N )	new_idents    M/usr/local/lib/python3.11/dist-packages/gevent/monkey/_patch_thread_gte313.py<lambda>z.Patcher.patch_active_threads.<locals>.<lambda>   s    I     _handle_os_thread_handler   )gevent.threadingr	   threading_mod_activevaluesgevent.threadr
   greenletr   _after_fork_set_greenlethasattrsetattrident_identgetattr(_make_existing_non_main_thread_join_funcjoin)selfr	   threadr
   r   handlehandle_attrs          r   patch_active_threadszPatcher.patch_active_threads   s0   777777(07799 	\ 	\F++----777777//////%E%E%E"&$$ZZ\\222'6#677 6"5KV444 &|wv{'C'C'IIIIIGGHLHLHZ\ \FKK	\ 	\r   c                      dd l }ddlm  j         j         j        |                                x_        dt          d          rd fd}  j        d|           d S )Nr   r   )
patch_itemr   r   c                     t                                                     ddlm}  	  |              n4#  ddlm}   |            j        gt          j                    R   Y nxY w G d d          }t           |                       	                                sJ t                                                    D ]}|j        s|u r|	                                r_t          |          }	 |                    d           n$# t          $ r |                                 Y nw xY w|	                                _	               n# t          $ r Y nw xY w 	d
j                   d S )Nr   )sleep)get_hubc                        e Zd Zd Zd Zd ZdS )jPatcher.patch_threading_shutdown_on_main_thread_not_already_patched.<locals>._shutdown.<locals>.FakeHandlec                     dS )NFr   r$   s    r   is_donezrPatcher.patch_threading_shutdown_on_main_thread_not_already_patched.<locals>._shutdown.<locals>.FakeHandle.is_doneF   s     5r   c                     d S r   r   r1   s    r   	_set_doneztPatcher.patch_threading_shutdown_on_main_thread_not_already_patched.<locals>._shutdown.<locals>.FakeHandle._set_doneH       Fr   c                     d S r   r   r1   s    r   r#   zoPatcher.patch_threading_shutdown_on_main_thread_not_already_patched.<locals>._shutdown.<locals>.FakeHandle.joinJ   r5   r   N)__name__
__module____qualname__r2   r4   r#   r   r   r   
FakeHandler/   E   sA        ! ! !      r   r:   gMbP?	_shutdown)r!   r4   geventr,   r-   print_exceptionsysexc_infor   is_alivelist	enumeratedaemonr#   RuntimeErrorr   orig_shutdown)r,   r-   r:   tr&   	_greenletr'   main_threadrE   r*   r$   r   s        r   r;   zVPatcher.patch_threading_shutdown_on_main_thread_not_already_patched.<locals>._shutdown3   s    K--77999$$$$$$FF +*****)		))EclnnEEEEEE        Kjjll;;;''))))) -113344  8 qK//jjll $Q44FE****'   ((*** jjll    J}k43EFFFFFs-   
6 /A':DD10D1

E 
E"!E"r;   )	r   apir*   rH   r   rE   r   rG   r   )	r$   r   r;   rG   r'   rH   rE   r*   r   s	   `  @@@@@@r   ;patch_threading_shutdown_on_main_thread_not_already_patchedzCPatcher.patch_threading_shutdown_on_main_thread_not_already_patched'   s    ######&**,4,?,?,A,AA	K); 344 	.-K4	G 4	G 4	G 4	G 4	G 4	G 4	G 4	G 4	G 4	G 4	Gl 	
4%{I>>>>>r   N)r7   r8   r9   r(   rJ   r   r   r   r   r      s:        \ \ \*B? B? B? B? B?r   r   )__doc__r>   gevent.exceptionsr   _patch_thread_commonr   r   r   r   r   <module>rN      s|     


 & & & & & & - - - - - -Z? Z? Z? Z? Z?k Z? Z? Z? Z? Z?r   