o
    ;gZ)                     @   s  d Z ddlZg dejdd dkrg dng  ZdgZddlZdZeg d	7 Zed
 e	edr7e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red d-ddZd.ddZd.ddZ d/dd Z!G d!d" d"Z"d#d$ Z#G d%d& d&eZ$e$ Z%Z&d'd( Z'e	ed)rej(Z)d-d*d)Z(ne*d) eee+ edd+Zee Z,e,*d, dS )0aK  
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_idZdaemon_threads_allowed)PYPY)copy_globals)
getcurrentGreenletExit)sleep)get_hub_if_exists)Greenlet)BoundedSemaphore)local)LoopExitRLockc                 C   s   | d u rt  } t| S N)r   id)Zgr r&   T/home/www/bk.finsightngr.online/venv20/lib/python3.10/site-packages/gevent/thread.pyr   J   s   r   r&   c                 C   s:   |d urt j| g|R i |}|S t j| g|R  }|S r$   )r   spawn)functionargskwargsgreenletr&   r&   r'   _start_new_greenletP   s
   r-   c                 C   s   t t| ||S r$   )r   r-   )r)   r*   r+   r&   r&   r'   r   W   s   r   Tc                 C   s,   t | }|durt|tsJ || |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.
    N)r-   
isinstancer   _set_greenlet)r)   handledaemonr,   r&   r&   r'   r   Z   s
   
r   c                   @   sV   e Zd Zdd ZdZdd Zdd Zdd	 Zed
d Z	dd Z
dddZdd ZdS )r   c                 O   s   dS )zDoes nothing; ignores argsNr&   )self_args_kwargsr&   r&   r'   __init__~   s    z_ThreadHandle.__init__Nc                 C   s&   ddl m} |d usJ ||| _d S )Nr   )ref)weakrefr6   _greenlet_ref)r2   gletr6   r&   r&   r'   r/      s   z_ThreadHandle._set_greenletc                 C   s   | j d ur	|   S d S r$   )r8   r2   r&   r&   r'   _get_greenlet   s
   z_ThreadHandle._get_greenletc                 C   s   |   }|d urA|t u rtdt|dr||S ddlm} d }|r*| | }|  sA|d ur9| |kr9d S td |  r.d S )NzCannot joint current threadjoinr   )timeMbP?)r;   r   RuntimeErrorhasattrr<   r=   is_doner   )r2   timeoutr9   r=   endr&   r&   r'   r<      s    



z_ThreadHandle.joinc                 C   s   |   }|d urt|S d S r$   )r;   r   r2   r9   r&   r&   r'   ident   s   z_ThreadHandle.identc                 C   s   |   }|d u r
dS |jS NT)r;   ZdeadrD   r&   r&   r'   rA      s   z_ThreadHandle.is_doneTc                 C   s   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.
        Nr>   )r8   r   )r2   Z	enter_hubr&   r&   r'   	_set_done   s   
z_ThreadHandle._set_donec                 C   s    d| j j| j jt| |  f S )Nz<%s.%s at 0x%x greenlet=%r>)	__class__
__module____name__r%   r;   r:   r&   r&   r'   __repr__   s   z_ThreadHandle.__repr__)T)rJ   rI   __qualname__r5   r8   r/   r;   r<   propertyrE   rA   rG   rK   r&   r&   r&   r'   r   {   s    

r   c                  G   s   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   )r3   r0   r&   r&   r'   r      s   r   c                       sJ   e Zd ZdZejZereZej	Z
 fddZedd Zd
dd	Z  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                    s   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)superr5   r:   rH   r&   r'   r5      s   zLockType.__init__c                 C      t r$   )	TypeError)clsr&   r&   r'   __init_subclass__   s   zLockType.__init_subclass__Tc                 C   s   |dkrd }|s|d urt d|d ur%|dk rt d|| jkr%tdz	t| ||}W n ty<   |r8 d}Y nw |sJ|sJt t urJt  |S )NrT   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   )r2   blockingrB   Zacquiredr&   r&   r'   rX      s&   	
	
zLockType.acquire)TrT   )rJ   rI   rL   __doc__
__thread__r   Z_OVER_RELEASE_ERRORr   r?   r   rV   r5   classmethodrS   rX   __classcell__r&   r&   rO   r'   r      s    		
r   c                   C   rP   r$   r   r&   r&   r&   r'   r   1  s   r   r   c                 C   s$   | d u rt  S | t  krt | S d S r$   )_original_stack_size)sizer&   r&   r'   r   8  s
   
)Z
only_namesZignore_missing_namesr   r$   )r&   NrF   )-rZ   sysversion_infoZ__implements__Z__imports__r   r[   Z
__target__appendr@   r   Zgevent._compatr   Zgevent._utilr   Z
gevent.hubr   r   r   Zgevent._hub_localr   Zgevent.greenletr   Zgevent.lockr    Zgevent.localr!   r   Zgevent.exceptionsr"   r   r-   r   r   r   r   r   r   r   r   r   r^   removeglobals__all__r&   r&   r&   r'   <module>   s\    










!YO

