
    iH                     l    d dl mZ d dlmZ dgZ G d d          Z e            Z G d d          ZdS )    )hubs)	greenletsEventc                       e Zd Zd ZdS )NOT_USEDc                     dS )Nr    selfs    9/usr/local/lib/python3.11/dist-packages/eventlet/event.py__repr__zNOT_USED.__repr__   s    z    N)__name__
__module____qualname__r   r	   r   r   r   r      s#            r   r   c                   r    e Zd ZdZdZdZd Zd Zd Zd Z	d Z
d Zdd	Zdd
ZddZddZddZd Zd ZdS )r   a  An abstraction where an arbitrary number of coroutines
    can wait for one event from another.

    Events are similar to a Queue that can only hold one item, but differ
    in two important ways:

    1. calling :meth:`send` never unschedules the current greenthread
    2. :meth:`send` can only be called once; create a new event to send again.

    They are good for communicating results between coroutines, and
    are the basis for how
    :meth:`GreenThread.wait() <eventlet.greenthread.GreenThread.wait>`
    is implemented.

    >>> from eventlet import event
    >>> import eventlet
    >>> evt = event.Event()
    >>> def baz(b):
    ...     evt.send(b + 1)
    ...
    >>> _ = eventlet.spawn_n(baz, 3)
    >>> evt.wait()
    4
    Nc                 T    t                      | _        |                                  d S N)set_waitersresetr
   s    r   __init__zEvent.__init__+   s    

r   c                     | j         j        t          t          |                     | j        | j        t          | j                  f}d|z  S )Nz)<%s at %s result=%r _exc=%r _waiters[%d]>)	__class__r   hexid_result_exclenr   )r   paramss     r   __str__zEvent.__str__/   s?    .)3r$xx==,	3t}+=+=?:VCCr   c                 \    | j         t          us
J d            t          | _         d | _        d S )Nz#Trying to re-reset() a fresh event.r   r   r   r
   s    r   r   zEvent.reset4   s2     |8+++-R+++			r   c                     | j         t          uS )a]   Return true if the :meth:`wait` call will return immediately.
        Used to avoid waiting for things that might take a while to time out.
        For example, you can put a bunch of events into a list, and then visit
        them all repeatedly, calling :meth:`ready` until one returns ``True``,
        and then you can :meth:`wait` on that one.)r   r   r
   s    r   readyzEvent.ready<   s     |8++r   c                     | j         d uS r   )r   r
   s    r   has_exceptionzEvent.has_exceptionD   s    y$$r   c                 0    | j         t          uo| j        d u S r   r#   r
   s    r   
has_resultzEvent.has_resultG   s    |8+A	T0AAr   c                 V    |                                  r|                                 S |S r   )r%   waitr   notreadys     r   pollz
Event.pollJ   s%    ::<< 	99;;r   c                 V    |                                  r|                                 S |S r   )r'   r+   r,   s     r   poll_exceptionzEvent.poll_exceptionT   s)     	99;;r   c                 V    |                                  r|                                 S |S r   )r)   r+   r,   s     r   poll_resultzEvent.poll_resultY   s'    ?? 	99;;r   c                    t          j                    }| j        t          u rt	          j                    }| j                            |           d}||                    || j	        dd|          }	 |
                                }||                                 || j                            |           S # | j                            |           w xY w| j         |j        | j          | j        S )a  Wait until another coroutine calls :meth:`send`.
        Returns the value the other coroutine passed to :meth:`send`.

        >>> import eventlet
        >>> evt = eventlet.Event()
        >>> def wait_on():
        ...    retval = evt.wait()
        ...    print("waited for {0}".format(retval))
        >>> _ = eventlet.spawn(wait_on)
        >>> evt.send('result')
        >>> eventlet.sleep(0)
        waited for result

        Returns immediately if the event has already occurred.

        >>> evt.wait()
        'result'

        When the timeout argument is present and not None, it should be a floating point number
        specifying a timeout for the operation in seconds (or fractions thereof).
        N)greenlet
getcurrentr   r   r   get_hubr   addschedule_call_local_do_sendswitchcanceldiscardr   throw)r   timeoutcurrenthubtimerresults         r   r+   z
Event.wait^   s    , %''<8##,..CMg&&&E"//dT[\\/$LLNNN%%g....%%g....9 GM49%%|s   2+B8 8Cc                    | j         t          u s
J d            || _         |t          |t                    s|f}|| _        t          j                    }| j        D ]*}|                    d| j	        | j         | j        |           +dS )au  Makes arrangements for the waiters to be woken with the
        result and then returns immediately to the parent.

        >>> from eventlet import event
        >>> import eventlet
        >>> evt = event.Event()
        >>> def waiter():
        ...     print('about to wait')
        ...     result = evt.wait()
        ...     print('waited for {0}'.format(result))
        >>> _ = eventlet.spawn(waiter)
        >>> eventlet.sleep(0)
        about to wait
        >>> evt.send('a')
        >>> eventlet.sleep(0)
        waited for a

        It is an error to call :meth:`send` multiple times on the same event.

        >>> evt.send('whoops') # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        AssertionError: Trying to re-send() an already-triggered event.

        Use :meth:`reset` between :meth:`send` s to reuse an event object.
        z/Trying to re-send() an already-triggered event.Nr   )
r   r   
isinstancetupler   r   r6   r   schedule_call_globalr9   )r   rB   excr@   waiters        r   sendz
Event.send   s    4 |x''')Z'''?:c5#9#9?'C	lnnm 	C 	CF$$4=$,	6C C C C	C 	Cr   c                 b    || j         v r%||                    |           d S  |j        |  d S d S r   )r   r:   r=   )r   rB   rG   rH   s       r   r9   zEvent._do_send   sI    T]""{f%%%%%c""""	 #"r   c                 .    |                      d|          S )a  Same as :meth:`send`, but sends an exception to waiters.

        The arguments to send_exception are the same as the arguments
        to ``raise``.  If a single exception object is passed in, it
        will be re-raised when :meth:`wait` is called, generating a
        new stacktrace.

           >>> from eventlet import event
           >>> evt = event.Event()
           >>> evt.send_exception(RuntimeError())
           >>> evt.wait()
           Traceback (most recent call last):
             File "<stdin>", line 1, in <module>
             File "eventlet/event.py", line 120, in wait
               current.throw(*self._exc)
           RuntimeError

        If it's important to preserve the entire original stack trace,
        you must pass in the entire :func:`sys.exc_info` tuple.

           >>> import sys
           >>> evt = event.Event()
           >>> try:
           ...     raise RuntimeError()
           ... except RuntimeError:
           ...     evt.send_exception(*sys.exc_info())
           ...
           >>> evt.wait()
           Traceback (most recent call last):
             File "<stdin>", line 1, in <module>
             File "eventlet/event.py", line 120, in wait
               current.throw(*self._exc)
             File "<stdin>", line 2, in <module>
           RuntimeError

        Note that doing so stores a traceback object directly on the
        Event object, which may cause reference cycles. See the
        :func:`sys.exc_info` documentation.
        N)rI   )r   argss     r   send_exceptionzEvent.send_exception   s    R yyt$$$r   r   )NN)r   r   r   __doc__r   r   r   r!   r   r%   r'   r)   r.   r0   r2   r+   rI   r9   rM   r	   r   r   r   r      s        0 GD  D D D
  , , ,% % %B B B      
   
& & & &P"C "C "C "CH# # #)% )% )% )% )%r   N)eventletr   eventlet.supportr   r4   __all__r   r   r	   r   r   <module>rR      s          2 2 2 2 2 2)       
 8::K% K% K% K% K% K% K% K% K% K%r   