
    i-                     
   d Z ddlZg dej        dd         dk    rg dng z   ZdgZddlZdZeg d	z  Ze                    d
            e	ed          re                    d           ej
        Z
ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ  e	ed          re                    d            e	ed          re                    d           d(dZd)dZd)dZ d*dZ! G d d          Z"d  Z# G d! d"e          Z$e$xZ%Z&d# Z' e	ed$          rej(        Z)d(d%Z(ne*                    d$            ee e+            ed&          Zeez   Z,e,*                    d'           dS )+aK  
Implementation of the standard :mod:`thread` module that spawns greenlets.

.. note::

    This module is a helper for :mod:`gevent.monkey` and is not
    intended to be used directly. For spawning greenlets in your
    applications, prefer higher level constructs like
    :class:`gevent.Greenlet` class or :func:`gevent.spawn`.
    N)allocate_lock	get_identexitLockType
stack_sizestart_new_thread_local   )      )start_joinable_threadlock_ThreadHandle_make_thread_handleerror_thread)TIMEOUT_MAXallocateexit_threadinterrupt_main	start_newget_native_iddaemon_threads_allowed)PYPY)copy_globals)
getcurrentGreenletExit)sleep)get_hub_if_exists)Greenlet)BoundedSemaphore)local)LoopExitRLockset_namec                 @    | t                      } t          |           S N)r   id)grs    8/usr/local/lib/python3.11/dist-packages/gevent/thread.pyr   r   O   s    	z\\b66M     c                 Z    |t          j        | g|R i |}nt          j        | g|R  }|S r(   )r!   spawn)functionargskwargsgreenlets       r+   _start_new_greenletr4   U   sE    >(<T<<<V<<>(2T222Or,   c                 >    t          t          | ||                    S r(   )r   r4   )r0   r1   r2   s      r+   r   r   \   s    (4@@AAAr,   Tc                     t          |           }|t                      }n:t          |t                    st          d          |j        rt          d          |                    |           |S )a  
    *For internal use only*: start a new thread.

    Like start_new_thread(), this starts a new thread calling the given function.
    Unlike start_new_thread(), this returns a handle object with methods to join
    or detach the given thread.
    This function is not for third-party code, please use the
    `threading` module instead. During finalization the runtime will not wait for
    the thread to exit if daemon is True. If handle is provided it must be a
    newly created thread._ThreadHandle instance.
    NzMust be a gevent thread handlezthread already started)r4   r   
isinstanceAssertionError_had_greenletRuntimeError_set_greenlet)r0   handledaemonr3   s       r+   r   r   _   sw    2 #8,,H ~.. 5=>>>		 53444
"""Mr,   c                   Z    e Zd Zd ZdZdZd Zd ZddZe	d             Z
d	 ZddZd ZdS )r   c                     dS )zDoes nothing; ignores argsNr-   )self_args_kwargss      r+   __init__z_ThreadHandle.__init__   s      r,   NFc                 H    ddl m} |J  ||          | _        d| _        d S )Nr   )refT)weakrefrE   _greenlet_refr9   )r@   gletrE   s      r+   r;   z_ThreadHandle._set_greenlet   s>     SYY!r,   c                 <    | j         |                                  nd S r(   )rG   r@   s    r+   _get_greenletz_ThreadHandle._get_greenlet   s)     !-    	
r,   c                    |dk    rd n|}| j         st          d          |                                 }||t                      u rt          d          t	          |d          r|                    |          S ddlm} d }|r |            |z   }|                                 s5| |            |k    rd S t          d           |                                 5d S )NrL   thread not startedzCannot join current threadjoinr   )timeMbP?)	r9   r:   rK   r   hasattrrO   rP   is_doner   )r@   timeoutrH   rP   ends        r+   rO   z_ThreadHandle.join   s    "R--$$W! 	53444!!##z||##"#?@@@tV$$ *yy))) "!!!!!C 'dffw&llnn ?ttvv||Fe llnn  tr,   c                 P    |                                  }|t          |          S d S r(   )rK   r   r@   rH   s     r+   identz_ThreadHandle.ident   s*    !!##T??"tr,   c                 @    |                                  }|dS |j        S NT)rK   deadrW   s     r+   rS   z_ThreadHandle.is_done   s%    !!##<4yr,   Tc                 f    | j         st          d          d| _        |rt          d           dS dS )a[  
        Mark the thread as complete.

        This releases our reference (if any) to our greenlet.

        By default, this will bounce back to the hub so that waiters
        in ``join`` can get notified. Set *enter_hub* to false not to
        do this. This private API is tightly coupled to our ``threading``
        implementation.
        rN   NrQ   )r9   r:   rG   r   )r@   	enter_hubs     r+   	_set_donez_ThreadHandle._set_done   sI     ! 	53444!  	%LLLLL	 	r,   c                 z    d| j         j        | j         j        t          |           |                                 fz  S )Nz<%s.%s at 0x%x greenlet=%r>)	__class__
__module____name__r)   rK   rJ   s    r+   __repr__z_ThreadHandle.__repr__   s<    ,N%N#tHH  	0
 
 	
r,   )rL   )T)rb   ra   __qualname__rC   rG   r9   r;   rK   rO   propertyrX   rS   r^   rc   r-   r,   r+   r   r      s        ) ) ) M M" " "
 
 
   @   X     *
 
 
 
 
r,   r   c                  d    t                      }|                    t                                 |S )z
    Called on 3.13 after forking in the child.
    Takes ``(module, ident)``, returns a handle object
    with that ident.
    )r   r;   r   )rA   r<   s     r+   r   r      s*     __F
&&&Mr,   c                   d     e Zd ZdZej        ZereZej	        Z
 fdZed             ZddZ xZS )r   z
    The basic lock type.

    .. versionchanged:: 24.10.1
       Subclassing this object is no longer allowed. This matches the
       Python 3 API.
    c                 H    t                                                       dS )z
        .. versionchanged:: 24.10.1
           No longer accepts arguments to pass to the super class. If you
           want a semaphore with a different count, use a semaphore class directly.
           This matches the Lock API of Python 3
        N)superrC   )r@   r`   s    r+   rC   zLockType.__init__  s!     	r,   c                     t           r(   )	TypeError)clss    r+   __init_subclass__zLockType.__init_subclass__  s    r,   TrL   c                 T   |dk    rd }|s|t          d          |/|dk     rt          d          || j        k    rt          d          	 t          j        | ||          }n# t
          $ r |r d}Y nw xY w|s,|s*t                      t                      urt                       |S )NrL   z/can't specify a timeout for a non-blocking callr   z'timeout value must be strictly positiveztimeout value is too largeF)	
ValueError_TIMEOUT_MAXOverflowErrorr"   acquirer$   r   r    r   )r@   blockingrT   acquireds       r+   rr   zLockType.acquire  s     b==G 	PG/NOOO{{ !JKKK***#$@AAA		'/hHHHH 	 	 	
  HHH	  
	 
	Z\\ARATAT-T-T GGGs   A% %A76A7)TrL   )rb   ra   rd   __doc__
__thread__r   _OVER_RELEASE_ERRORr   r:   r   rp   rC   classmethodrm   rr   __classcell__)r`   s   @r+   r   r      s          %* +* )L       [+ + + + + + + +r,   r   c                      t           r(   r   r-   r,   r+   r   r   K  s    
r,   r   c                 h    | t                      S | t                      k    rt          |           S d S r(   )_original_stack_size)sizes    r+   r   r   R  s;    <')))&(((('--- )(r,   )
only_namesignore_missing_namesr	   r(   )r-   NrZ   )-ru   sysversion_info__implements____imports__r   rv   
__target__appendrR   r   gevent._compatr   gevent._utilr   
gevent.hubr   r   r   gevent._hub_localr    gevent.greenletr!   gevent.lockr"   gevent.localr#   r	   gevent.exceptionsr$   r   r4   r   r   r   r   r   r   r   r   r   r|   removeglobals__all__r-   r,   r+   <module>r      sc  	 	 


   	bqbW$$   
+$ i    
        ? # # # 7:/00 1/000       % % % % % % ! ! ! ! ! ! # # # # # #       / / / / / / $ $ $ $ $ $ ( ( ( ( ( ( ( ( ( ( ( ( & & & & & & 7:w  w 7:z"" #z"""      B B B B% % % %Nf
 f
 f
 f
 f
 f
 f
 f
P	 	 	J J J J J J J J^      7:|$$ (%0. . . . . ,'''l:wwyy&1046 6 6 ;
& x     r,   