
    !niH                     X    d dl mZ d dlmZ dgZ G d d      Z e       Z G d d      Zy)    )hubs)	greenletsEventc                       e Zd Zd Zy)NOT_USEDc                      y)Nr    selfs    N/home/homepc/tiktok-worker/venv/lib/python3.12/site-packages/eventlet/event.py__repr__zNOT_USED.__repr__   s        N)__name__
__module____qualname__r   r	   r   r   r   r      s    r   r   c                   p    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y)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                 B    t               | _        | j                          y 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__/   sC    ..))3r$x=,,		3t}}+=?:VCCr   c                 Z    | j                   t        usJ d       t        | _         d | _        y )Nz#Trying to re-reset() a fresh event.r   r   r   r
   s    r   r   zEvent.reset4   s*     ||8+R-R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    yy$$r   c                 F    | j                   t        uxr | j                  d u S r   r#   r
   s    r   
has_resultzEvent.has_resultG   s    ||8+A		T0AAr   c                 F    | j                         r| j                         S |S r   )r%   waitr   notreadys     r   pollz
Event.pollJ   s    ::<99;r   c                 F    | j                         r| j                         S |S r   )r'   r+   r,   s     r   poll_exceptionzEvent.poll_exceptionT   s    99;r   c                 F    | j                         r| j                         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                  j                  |       d}||j                  || j                  dd|      }	 |j                         }||j                          || j                  j                  |       S | j                   |j                  | j                    | j                  S # | j                  j                  |       w xY w)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MMg&E"//dT[\/$LLN%%g.99 GMM499%|| %%g.s   :#C* *Dc                 ,   | j                   t        u sJ d       || _         |t        |t              s|f}|| _        t        j                         }| j                  D ]5  }|j                  d| j                  | j                   | j                  |       7 y)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)ZZ'?:c5#9'C	llnmm 	CF$$4==$,,		6C	Cr   c                 h    || j                   v r$||j                  |       y  |j                  |  y y r   )r   r:   r=   )r   rB   rG   rH   s       r   r9   zEvent._do_send   s2    T]]"{f%c"	 #r   c                 &    | j                  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      sY    0 GDD
,%B

&P"CH#)%r   N)eventletr   eventlet.supportr   r4   __all__r   r   r	   r   r   <module>rR      s1     2) 
 :K% K%r   