o
    0׾g                     @   sL  d dl mZmZ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 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' g dZ(e)dj*e+ d< dd e+ d< e'j,e+ d< dd e+ d< dd e+ d< dd e+ d< d d e+ d!< d"d e+ d#< erd d$l-Z-e-j.Z/G d%d& d&e0Z1G d'd( d(e1Z2G d)d* d*e1Z3G d+d, d,e0Z4d-d. Z5ej6Z7G d/d0 d0eZ8G d1d2 d2e0Z9e9 Z:e9 Z;d3d4 Z<dEd6d7Z=d8d9 Z>d:d; Z?d<d= Z@d$aAed>d$fd?d@ZBdAdB ZCeC  d dCl!mDZD eDeE dD d$S )F    )absolute_importprint_functiondivision)	_getframe)exc_info)ref)greenlet)GreenletExit)reraise)PYPY)dump_traceback)load_traceback)InvalidSwitchError)iwait_on_objects)wait_on_objects)Timeout)config)readproperty)get_hub_noargs)_waiter)Greenletjoinallkillallr   
getcurrentc                   C      d S N r   r   r   Y/var/www/html/backend_erp/backend_erp_env/lib/python3.10/site-packages/gevent/greenlet.py<lambda>-   s    r   greenlet_initWaiterc                 C      | j S r   parentsr   r   r   r   5       
get_my_hubc                 C   r!   r   r"   r$   r   r   r   r   8   r&   get_generic_parentc                 C   r!   r   )f_codeframer   r   r   r   ;   r&   Gevent_PyFrame_GetCodec                 C   r!   r   )f_linenor*   r   r   r   r   <   r&   Gevent_PyFrame_GetLineNumberc                 C   r!   r   )f_backr*   r   r   r   r   =   r&   Gevent_PyFrame_GetBackNc                   @   sN   e Zd ZdZdgZdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd ZdS )SpawnedLinkzj
    A wrapper around link that calls it in another greenlet.

    Can be called only from main loop.
    callbackc                 C   s    t |std|f || _d S )NExpected callable: %r)callable	TypeErrorr2   selfr2   r   r   r   __init__M   s   
zSpawnedLink.__init__c                 C   s   t | jt }|| d S r   )r   r2   get_hubswitch)r7   sourcegr   r   r   __call__R   s   zSpawnedLink.__call__c                 C   
   t | jS r   )hashr2   r7   r   r   r   __hash__V      
zSpawnedLink.__hash__c                 C   s   | j t|d|kS Nr2   )r2   getattr)r7   otherr   r   r   __eq__Y   s   zSpawnedLink.__eq__c                 C   r>   r   )strr2   r@   r   r   r   __str__\   rB   zSpawnedLink.__str__c                 C   r>   r   )reprr2   r@   r   r   r   __repr___   rB   zSpawnedLink.__repr__c                 C   s   |dksJ t | j|S rC   )rD   r2   )r7   itemr   r   r   __getattr__b   s   zSpawnedLink.__getattr__N)__name__
__module____qualname____doc__	__slots__r8   r=   rA   rF   rH   rJ   rL   r   r   r   r   r1   E   s    r1   c                   @      e Zd ZdZg Zdd ZdS )SuccessSpawnedLinkz|A wrapper around link that calls it in another greenlet only if source succeed.

    Can be called only from main loop.
    c                 C   s   |  r
t| |S d S r   
successfulr1   r=   r7   r;   r   r   r   r=   n      zSuccessSpawnedLink.__call__NrM   rN   rO   rP   rQ   r=   r   r   r   r   rS   g       rS   c                   @   rR   )FailureSpawnedLinkz{A wrapper around link that calls it in another greenlet only if source failed.

    Can be called only from main loop.
    c                 C   s   |  s
t| |S d S r   rT   rV   r   r   r   r=   z   rW   zFailureSpawnedLink.__call__NrX   r   r   r   r   rZ   s   rY   rZ   c                   @   s$   e Zd ZdZdd Zedd ZdS )_Frame)r)   r-   r/   c                 C   s   d | _ d | _d| _d S Nr   )r)   r/   r-   r@   r   r   r   r8      s   
z_Frame.__init__c                 C   r   r   r   r@   r   r   r   	f_globals   s   z_Frame.f_globalsN)rM   rN   rO   rQ   r8   propertyr]   r   r   r   r   r[   ~   s
    r[   c                 C   s   zt  }W n ty   d }Y nw d }d }| rE|d urE| d8 } t }t||_t||_|d ur3||_|}|d u r;|}t|}| rE|d us|S )N   )	sys_getframe
ValueErrorr[   r,   r)   r.   r-   r/   r0   )limitr+   newest_Framenewer_Frameolder_Framer   r   r   _extract_stack   s(   



rf   c                   @   s  e Zd ZdZdZdfddZdd Zedd	 Ze	d
d Z
dd Zedd Zdd ZzeZW n	 ey8   Y nw erBedd Znedd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zed#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zed-d. Zed/d0 Zd1d2 Z d3d4 Z!d5d6 Z"e#d7d8 Z$e#d9d: Z%e&d;d< Z'e&d=d> Z(d?d@ Z)e*dAdfdBdCZ+dgdDdEZ,dfdFdGZ-dHdI Z.dJdK Z/dLdM Z0dNdO Z1dPdQ Z2dRdS Z3dTdU Z4dVdW Z5dXdY Z6e7fdZd[Z8d\d] Z9d^d_ Z:e;fd`daZ<e=fdbdcZ>ddde Z?dS )hr   z@
    A light-weight cooperatively-scheduled execution unit.
    
   Nc                 O   s   t | dt  |dur|| _t| jstd|| _|| _d| _d| _d| _	d| _
g | _d| _d| _tjrbt }t|| _z|j| _W n tyY   i | _t|durW| j|_Y nw t| j| _dS d| _d| _d| _dS )a  
        :param args: The arguments passed to the ``run`` function.
        :param kwargs: The keyword arguments passed to the ``run`` function.
        :keyword callable run: The callable object to run. If not given, this object's
            `_run` method will be invoked (typically defined by subclasses).

        .. versionchanged:: 1.1b1
            The ``run`` argument to the constructor is now verified to be a callable
            object. Previously, passing a non-callable object would fail after the greenlet
            was spawned.

        .. versionchanged:: 1.3b1
           The ``GEVENT_TRACK_GREENLET_TREE`` configuration value may be set to
           a false value to disable ``spawn_tree_locals``, ``spawning_greenlet``,
           and ``spawning_stack``. The first two will be None in that case, and the
           latter will be empty.

        .. versionchanged:: 1.5
           Greenlet objects are now more careful to verify that their ``parent`` is really
           a gevent hub, raising a ``TypeError`` earlier instead of an ``AttributeError`` later.

        .. versionchanged:: 20.12.1
           Greenlet objects now function as context managers. Exiting the ``with`` suite
           ensures that the greenlet has completed by :meth:`joining <join>`
           the greenlet (blocking, with
           no timeout). If the body of the suite raises an exception, the greenlet is
           :meth:`killed <kill>` with the default arguments and not joined in that case.
        Nz.The run argument or self._run must be callable)_greenlet__init__r9   _runr4   r5   argskwargsvalue_start_event	_notifier_formatted_info_links_ident	_exc_infoGEVENT_CONFIGtrack_greenlet_treer   wrefspawning_greenletspawn_tree_localsAttributeErrorr(   rf   spawning_stack_limitspawning_stack)r7   runrj   rk   spawnerr   r   r   r8      s:   C



zGreenlet.__init__c                 C   s   t | }|j}|| S r   )r'   ident_registry	get_ident)r7   hubregr   r   r   _get_minimal_ident;  s   	
zGreenlet._get_minimal_identc                 C   s   | j du r
|  | _ | j S )a  
        A small, unique non-negative integer that identifies this object.

        This is similar to :attr:`threading.Thread.ident` (and `id`)
        in that as long as this object is alive, no other greenlet *in
        this hub* will have the same id, but it makes a stronger
        guarantee that the assigned values will be small and
        sequential. Sometime after this object has died, the value
        will be available for reuse.

        To get ids that are unique across all hubs, combine this with
        the hub's (``self.parent``) ``minimal_ident``.

        Accessing this property from threads other than the thread running
        this greenlet is not defined.

        .. versionadded:: 1.3a2

        N)rq   r   r@   r   r   r   minimal_identI  s   

zGreenlet.minimal_identc                 C   s   d| j f S )aL  
        The greenlet name. By default, a unique name is constructed using
        the :attr:`minimal_ident`. You can assign a string to this
        value to change it. It is shown in the `repr` of this object if it
        has been assigned to or if the `minimal_ident` has already been generated.

        .. versionadded:: 1.3a2
        .. versionchanged:: 1.4
           Stop showing generated names in the `repr` when the ``minimal_ident``
           hasn't been requested. This reduces overhead and may be less confusing,
           since ``minimal_ident`` can get reused.
        zGreenlet-%d)r   r@   r   r   r   named  s   zGreenlet.namec                 C   s   t | j  d S r   )r
   r   r@   r   r   r   _raise_exceptiont  s   zGreenlet._raise_exceptionc                 C   s   t | }|jS r   )r'   loopr7   r   r   r   r   r   w  s   zGreenlet.loopc                 C   s   | j d uo	| jd u S r   )rm   rr   r@   r   r   r   __nonzero__}  s   zGreenlet.__nonzero__c                 C   s0   | j rdS |  s|  rdS | jot|  S )zDBoolean indicating that the greenlet is dead and will not run again.FT)_greenlet__main"_Greenlet__start_cancelled_by_kill_Greenlet__started_but_aborted_greenlet__started_continulet
is_pendingr@   r   r   r   dead  s
   zGreenlet.deadc                 C   s   |   p|  ptj| S )a  
            Boolean indicating that the greenlet is dead and will not run again.

            This is true if:

            1. We were never started, but were :meth:`killed <kill>`
               immediately after creation (not possible with :meth:`spawn`); OR
            2. We were started, but were killed before running; OR
            3. We have run and terminated (by raising an exception out of the
               started function or by reaching the end of the started function).
            )r   r   r   r   __get__r@   r   r   r   r     s
   
c                 C   s
   | j d u S r   )rm   r@   r   r   r   __never_started_or_killed  rB   z"Greenlet.__never_started_or_killedc                 C   s    | j d uo| j jpt| j ddS )NactiveF)rm   pendingrD   r@   r   r   r   __start_pending  s   
zGreenlet.__start_pendingc                 C   
   | j tu S r   )rm   _cancelled_start_eventr@   r   r   r   __start_cancelled_by_kill  rB   z"Greenlet.__start_cancelled_by_killc                 C   r   r   )rm   _start_completed_eventr@   r   r   r   __start_completed  rB   zGreenlet.__start_completedc                 C   s(   |    o|   o|   o|   S r   )"_Greenlet__never_started_or_killedr   _Greenlet__start_completed_Greenlet__start_pendingr@   r   r   r   __started_but_aborted  s   
zGreenlet.__started_but_abortedc                 C   s(   | j d u rt| _ | j   | j   d S r   )rm   r   stopcloser@   r   r   r   __cancel_start  s   

zGreenlet.__cancel_startc                 C   s   | j d u r^| jr`t|dkr+|d }t|tr#t|tr#|| d f}nt||d f}n|s3tt d f}t|d tsNtd| dd l	}|
  tt|d f}t|d tsWJ | | d S d S d S )Nr_   r   zRANDOM CRAP)rr   r   len
isinstancetype
issubclassBaseExceptionr	   print	tracebackprint_stack_Greenlet__report_error)r7   rj   argr   r   r   r   __handle_death_before_start  s   	

z$Greenlet.__handle_death_before_startc                 C   s   t | S r   )boolr@   r   r   r   started  s   zGreenlet.startedc                 C   s   | j p| jduS )a  
        Return a true value if and only if the greenlet has finished
        execution.

        .. versionchanged:: 1.1
            This function is only guaranteed to return true or false *values*, not
            necessarily the literal constants ``True`` or ``False``.
        N)r   rr   r@   r   r   r   ready  s   	zGreenlet.readyc                 C   s   | j duo| j d du S )a  
        Return a true value if and only if the greenlet has finished execution
        successfully, that is, without raising an error.

        .. tip:: A greenlet that has been killed with the default
            :class:`GreenletExit` exception is considered successful.
            That is, ``GreenletExit`` is not considered an error.

        .. note:: This function is only guaranteed to return true or false *values*,
              not necessarily the literal constants ``True`` or ``False``.
        Nr_   rr   r@   r   r   r   rU     s   zGreenlet.successfulc                 C   sd   | j j}d| jvr| jd u rd}nd| jf }d||tt| f }|  }|r.|d| 7 }|d S )Nr    z "%s" z
<%s%sat %sz: >)	__class__rM   __dict__rq   r   hexid_formatinfo)r7   	classnamer   result	formattedr   r   r   rJ     s   zGreenlet.__repr__c                 C   s   | j }|d ur	|S | j}t|dd }|| u rd}n|d ur"t|}n
t|ddp+t|}|}g }| jr;dd | jD }| jrK|dd | j D  |rX|dd	| d
 7 }|| _ |S )N__self__ri   rM    c                 S   s   g | ]
}t |d d qS )N2   rI   ).0xr   r   r   
<listcomp>0  s    z(Greenlet._formatinfo.<locals>.<listcomp>c                 S   s(   g | ]\}}d |t |dd f qS )z%s=%sNr   r   )r   keyrl   r   r   r   r   2  s   ( (z, ))	ro   ri   rD   rI   rj   rk   extenditemsjoin)r7   infofuncim_selffuncnamer   rj   r   r   r   r     s(   
zGreenlet._formatinfoc                 C   s   | j dur
| j d S dS )z
        Holds the exception instance raised by the function if the
        greenlet has finished with an error. Otherwise ``None``.
        Nr_   r   r@   r   r   r   	exception9  s   zGreenlet.exceptionc                 C   sJ   | j }|dur!|d dur#|d |d |d rt|d fS dfS dS dS )z
        Holds the exc_info three-tuple raised by the function if the
        greenlet finished with an error. Otherwise a false value.

        .. note:: This is a provisional API and may change.

        .. versionadded:: 1.1
        Nr   r_      )rr   r   )r7   eir   r   r   r   A  s   
zGreenlet.exc_infoc              	   G   sN   |    z| jstj| g|R   W | | dS W | | dS | | w )a  Immediately switch into the greenlet and raise an exception in it.

        Should only be called from the HUB, otherwise the current greenlet is left unscheduled forever.
        To raise an exception in a safe manner from any greenlet, use :meth:`kill`.

        If a greenlet was started but never switched to yet, then also
        a) cancel the event that will start it
        b) fire the notifications as if an exception was raised in a greenlet
        N)_Greenlet__cancel_startr   r   throw$_Greenlet__handle_death_before_start)r7   rj   r   r   r   r   T  s   
zGreenlet.throwc                 C   s2   | j du rt|  t| }|j| j| _ dS dS )z3Schedule the greenlet to run in this loop iterationN)rm   _call_spawn_callbacksr'   r   run_callbackr:   r   r   r   r   startj  s
   
zGreenlet.startc                 C   s>   | j du rt|  t| }|j|| _ | j | j dS dS )z
        start_later(seconds) -> None

        Schedule the greenlet to run in the future loop iteration
        *seconds* later
        N)rm   r   r'   r   timerr   r:   )r7   secondsr   r   r   r   start_laterq  s   
zGreenlet.start_laterc                 C   s   t du rt a t |  dS )ac  
        add_spawn_callback(callback) -> None

        Set up a *callback* to be invoked when :class:`Greenlet` objects
        are started.

        The invocation order of spawn callbacks is unspecified.  Adding the
        same callback more than one time will not cause it to be called more
        than once.

        .. versionadded:: 1.4.0
        N)_spawn_callbackssetaddr2   r   r   r   add_spawn_callback~  s   zGreenlet.add_spawn_callbackc                 C   s&   t durt |  t sda dS dS dS )a#  
        remove_spawn_callback(callback) -> None

        Remove *callback* function added with :meth:`Greenlet.add_spawn_callback`.
        This function will not fail if *callback* has been already removed or
        if *callback* was never added.

        .. versionadded:: 1.4.0
        N)r   discardr   r   r   r   remove_spawn_callback  s   
zGreenlet.remove_spawn_callbackc                 O   s   | |i |}|   |S )a  
        spawn(function, *args, **kwargs) -> Greenlet

        Create a new :class:`Greenlet` object and schedule it to run ``function(*args, **kwargs)``.
        This can be used as ``gevent.spawn`` or ``Greenlet.spawn``.

        The arguments are passed to :meth:`Greenlet.__init__`.

        .. versionchanged:: 1.1b1
            If a *function* is given that is not callable, immediately raise a :exc:`TypeError`
            instead of spawning a greenlet that will raise an uncaught TypeError.
        )r   )clsrj   rk   r<   r   r   r   spawn  s   zGreenlet.spawnc                 O   s8   | t u r|sd|vrtd| |i |}|| |S )a  
        spawn_later(seconds, function, *args, **kwargs) -> Greenlet

        Create and return a new `Greenlet` object scheduled to run ``function(*args, **kwargs)``
        in a future loop iteration *seconds* later. This can be used as ``Greenlet.spawn_later``
        or ``gevent.spawn_later``.

        The arguments are passed to :meth:`Greenlet.__init__`.

        .. versionchanged:: 1.1b1
           If an argument that's meant to be a function (the first argument in *args*, or the ``run`` keyword )
           is given to this classmethod (and not a classmethod of a subclass),
           it is verified to be callable. Previously, the spawned greenlet would have failed
           when it started running.
        r{   r   )r   r5   r   )r   r   rj   rk   r<   r   r   r   spawn_later  s
   
zGreenlet.spawn_laterc                 C   sJ   |    |   | j}|r#t|trt|dkr|}n|f}| | |S N   )r   _Greenlet__freer   r   tupler   r   )r7   r   r   rj   r   r   r   _maybe_kill_before_start  s   
z!Greenlet._maybe_kill_before_startTc                 C   sd   |  |s.|  rdS |rt nd}t| }|jt| || |dur0|  | | dS dS dS )a  
        Raise the ``exception`` in the greenlet.

        If ``block`` is ``True`` (the default), wait until the greenlet
        dies or the optional timeout expires; this may require switching
        greenlets.
        If block is ``False``, the current greenlet is not unscheduled.

        This function always returns ``None`` and never raises an error. It
        may be called multpile times on the same greenlet object, and may be
        called on an unstarted or dead greenlet.

        .. note::

            Depending on what this greenlet is executing and the state
            of the event loop, the exception may or may not be raised
            immediately when this greenlet resumes execution. It may
            be raised on a subsequent green call, or, if this greenlet
            exits before making such a call, it may not be raised at
            all. As of 1.1, an example where the exception is raised
            later is if this greenlet had called :func:`sleep(0)
            <gevent.sleep>`; an example where the exception is raised
            immediately is if this greenlet had called
            :func:`sleep(0.1) <gevent.sleep>`.

        .. caution::

            Use care when killing greenlets. If the code executing is not
            exception safe (e.g., makes proper use of ``finally``) then an
            unexpected exception could result in corrupted state. Using
            a :meth:`link` or :meth:`rawlink` (cheaper) may be a safer way to
            clean up resources.

        See also :func:`gevent.kill` and :func:`gevent.killall`.

        :keyword type exception: The type of exception to raise in the greenlet. The default
            is :class:`GreenletExit`, which indicates a :meth:`successful` completion
            of the greenlet.

        .. versionchanged:: 0.13.0
            *block* is now ``True`` by default.
        .. versionchanged:: 1.1a2
            If this greenlet had never been switched to, killing it will
            prevent it from *ever* being switched to. Links (:meth:`rawlink`)
            will still be executed, though.
        .. versionchanged:: 20.12.1
            If this greenlet is :meth:`ready`, immediately return instead of
            requiring a trip around the event loop.
        N)	r   r   r    r'   r   r   _killgetr   )r7   r   blocktimeoutwaiterr   r   r   r   kill  s   
2zGreenlet.killc                 C   s   |   r|  r| jS |   |st t j}| | z$t|}zt	|  }|| ur5t
d|f W |  n|  w W n	   | |  |   r\|  rV| jS |   dS dS )a  
        get(block=True, timeout=None) -> object

        Return the result the greenlet has returned or re-raise the
        exception it has raised.

        If block is ``False``, raise :class:`gevent.Timeout` if the
        greenlet is still alive. If block is ``True``, unschedule the
        current greenlet until the result is available or the timeout
        expires. In the latter case, :class:`gevent.Timeout` is
        raised.
        z&Invalid switch into Greenlet.get(): %rN)r   rU   rl   r   r   r   r:   rawlink_start_new_or_dummyr'   r   cancelunlink)r7   r   r   r:   tr   r   r   r   r     s0   


zGreenlet.getc              
   C   s   |   rdS t j}| | z$t|}zt|  }|| ur'td|f W |  W dS |  w  tyP } z| 	| ||urE W Y d}~dS d}~w   | 	|  )z
        join(timeout=None) -> None

        Wait until the greenlet finishes or *timeout* expires. Return
        ``None`` regardless.
        Nz'Invalid switch into Greenlet.join(): %r)
r   r   r:   r   r   r   r'   r   r   r   )r7   r   r:   r   r   exr   r   r   r   A  s*   



zGreenlet.joinc                 C   s   | S r   r   r@   r   r   r   	__enter__]     zGreenlet.__enter__c                 C   s>   |d u rz|    W |   d S |   w | |||f d S r   )r   r   )r7   r   vtbr   r   r   __exit__`  s
   
zGreenlet.__exit__c                 C   s<   d| _ || _| jr| jst| }|j| j| _d S d S d S )N)NNN)rr   rl   rp   rn   r'   r   r   _notify_links)r7   r   r   r   r   r   __report_resulti  s   zGreenlet.__report_resultc                 C   s   t |d tr| |d  d S zt|d }W n   d }Y |d |d |f| _t| }| jr;| js;|j	| j
| _z|j| g|R   W ~d S ~w )Nr_   r   r   )r   r	   _Greenlet__report_resultr   rr   r'   rp   rn   r   r   r   handle_error)r7   r   r   r   r   r   r   __report_errorp  s   
zGreenlet.__report_errorc                 C   sp   z2|    t| _z| j| ji | j}W n   | t  Y n| | W | 	  d S W | 	  d S | 	  w r   )
r   r   rm   ri   rj   rk   r   sys_exc_infor   r   )r7   r   r   r   r   r{     s   zGreenlet.runc                 C   s0   z| ` W n	 ty   Y nw d| _| j  d S )Nr   )ri   rx   rj   rk   clearr@   r   r   r   __free  s   zGreenlet.__freec                 C   s   dS )a8  
        Subclasses may override this method to take any number of
        arguments and keyword arguments.

        .. versionadded:: 1.1a3
            Previously, if no callable object was
            passed to the constructor, the spawned greenlet would later
            fail with an AttributeError.
        Nr   r@   r   r   r   ri     s   zGreenlet._runc                 C   r>   r   )r   rp   r@   r   r   r   	has_links  rB   zGreenlet.has_linksc                 C   s^   t |std|f | j| |  r)| jr+| js-t| }|j| j	| _dS dS dS dS )a  
        Register a callable to be executed when the greenlet finishes
        execution.

        The *callback* will be called with this instance as an
        argument.

        The *callback* will be called even if linked after the greenlet
        is already ready().

        .. caution::
            The *callback* will be called in the hub and
            **MUST NOT** raise an exception.
        r3   N)
r4   r5   rp   appendr   rn   r'   r   r   r   )r7   r2   r   r   r   r   r     s   zGreenlet.rawlinkc                 C   s   |  || dS )au  
        Link greenlet's completion to a callable.

        The *callback* will be called with this instance as an
        argument once this greenlet is dead. A callable is called in
        its own :class:`greenlet.greenlet` (*not* a
        :class:`Greenlet`).

        The *callback* will be called even if linked after the greenlet
        is already ready().
        N)r   r7   r2   r1   r   r   r   link  s   zGreenlet.linkc                 C   s(   z	| j | W dS  ty   Y dS w )z:Remove the callback set by :meth:`link` or :meth:`rawlink`N)rp   removera   r6   r   r   r   r     s
   zGreenlet.unlinkc                 C   s   | j dd= dS )zL
        Remove all the callbacks.

        .. versionadded:: 1.3a2
        N)rp   r@   r   r   r   
unlink_all  s   zGreenlet.unlink_allc                 C      | j ||d dS )zy
        Like :meth:`link` but *callback* is only notified when the greenlet
        has completed successfully.
        r1   Nr  r   r   r   r   
link_value     zGreenlet.link_valuec                 C   r  )z
        Like :meth:`link` but *callback* is only notified when the
        greenlet dies because of an unhandled exception.
        r  Nr  r   r   r   r   link_exception  r  zGreenlet.link_exceptionc                 C   sR   | j r'| j d}z||  W n   t| j|| fgt R   Y | j sd S d S r\   )rp   popr'   r   r   )r7   r  r   r   r   r     s   zGreenlet._notify_linksr   )TN)@rM   rN   rO   rP   ry   r8   r   r^   r   r   r   r   r   r   __bool__	NameError_PYPYr   r   r   r   r   r   r   r   r   r   rU   rJ   r   r   r   r   r   r   staticmethodr   r   classmethodr   r   r   r	   r   r   r   r   r   r   r   r{   r   ri   r   r   r1   r  r   r  rS   r  rZ   r	  r   r   r   r   r   r      s    
 




#







=
,	r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )_dummy_eventr   r   c                 C   s   d | _ | _d S )NFr  r@   r   r   r   r8   
  s   z_dummy_event.__init__c                 C   r   r   r   r@   r   r   r   r     r   z_dummy_event.stopc                 C   s   t d)NzCannot start the dummy event)AssertionError)r7   cbr   r   r   r     s   z_dummy_event.startc                 C   r   r   r   r@   r   r   r   r     r   z_dummy_event.closeN)rM   rN   rO   rQ   r8   r   r   r   r   r   r   r   r    s    r  c                 C   sl   zt |trt|dkr| j|  n| | W n   t| j| gt R   Y |d ur4|d  d S d S r   )r   r   r   r   r'   r   r   r:   )gletr   r   r   r   r   r     s   
r   Fc                 C   sb   |s	t | ||dS g }t| ||dD ]}t|dddur)t|dr&|  n|j|| q|S )a5  
    Wait for the ``greenlets`` to finish.

    :param greenlets: A sequence (supporting :func:`len`) of greenlets to wait for.
    :keyword float timeout: If given, the maximum number of seconds to wait.
    :return: A sequence of the greenlets that finished before the timeout (if any)
        expired.
    )r   countr   Nr   )waitiwaitrD   hasattrr   r   r   )	greenletsr   raise_errorr  doneobjr   r   r   r   )  s   	

r   c                 C   sb   g }| D ]%}|j s)z|| W n   t|j|gt R   Y |j s)|| q|| d S r   )r   r   r'   r   r   r   r:   )r  r   r   diehardsr<   r   r   r   	_killall3@  s   
r  c                 C   sF   | D ]}|j s z|| W q   t|j|gt R   Y qqd S r   )r   r   r'   r   r   )r  r   r<   r   r   r   _killallM  s   r  c                 C   s"   t d urt D ]}||  qd S d S r   )r   )grr  r   r   r   r   V  s
   
r   Tc              	   C   s   g }| D ]}z|j }W n ty   || Y qw ||s#|| q|s(dS |j}|r]t }|t||| t|}	z|	 }
|
rQt
|
dd W |	  dS W |	  dS |	  w |t|| dS )ax  
    Forceably terminate all the *greenlets* by causing them to raise *exception*.

    .. caution:: Use care when killing greenlets. If they are not prepared for exceptions,
       this could result in corrupted state.

    :param greenlets: A **bounded** iterable of the non-None greenlets to terminate.
       *All* the items in this iterable must be greenlets that belong to the same hub,
       which should be the hub for this current thread. If this is a generator or iterator
       that switches greenlets, the results are undefined.
    :keyword exception: The type of exception to raise in the greenlets. By default this is
        :class:`GreenletExit`.
    :keyword bool block: If True (the default) then this function only returns when all the
        greenlets are dead; the current greenlet is unscheduled during that process.
        If greenlets ignore the initial exception raised in them,
        then they will be joined (with :func:`gevent.joinall`) and allowed to die naturally.
        If False, this function returns immediately and greenlets will raise
        the exception asynchronously.
    :keyword float timeout: A time in seconds to wait for greenlets to die. If given, it is
        only honored when ``block`` is True.
    :raise Timeout: If blocking and a timeout is given that elapses before
        all the greenlets are dead.

    .. versionchanged:: 1.1a2
        *greenlets* can be any iterable of greenlets, like an iterator or a set.
        Previously it had to be a list or tuple.
    .. versionchanged:: 1.5a3
        Any :class:`Greenlet` in the *greenlets* list that hadn't been switched to before
        calling this method will never be switched to. This makes this function
        behave like :meth:`Greenlet.kill`. This does not apply to raw greenlets.
    .. versionchanged:: 1.5a3
        Now accepts raw greenlets created by :func:`gevent.spawn_raw`.
    NF)r  )r   rx   r   r   r    r   r  r   r   r   r   r   r  )r  r   r   r   need_killedr  r   r   r   r   aliver   r   r   r   _  s2   #


r   c                   C   s
   t   d S r   )r   r   r   r   r   _init  rB   r#  )import_c_accelzgevent._greenlet)NFN)F
__future__r   r   r   sysr   r`   r   r   weakrefr   ru   r   r	   gevent._compatr
   r   r  gevent._tblibr   r   gevent.exceptionsr   gevent._hub_primitivesr   r  r   r  gevent.timeoutr   gevent._configr   rs   gevent._utilr   gevent._hub_localr   r9   geventr   __all__
__import__r   localsr    _continuation
continuletr   objectr1   rS   rZ   r[   rf   r8   rh   r   r  r   r   r   r   r  r  r   r   r   r#  r$  globalsr   r   r   r   <module>   sr   "#      \
	E