
    <|h                          d 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j                  eg d      \  ZZZddZ G d	 d
e      Z G d de      Z G d de      Zy)z
A small selection of primitives that always work with
native threads. This has very limited utility and is
targeted only for the use of gevent's threadpool.
    )absolute_import)deque)monkey)thread_mod_name)LockQueueEmptyTimeout)start_new_threadallocate_lock	get_identc                 f    t        |       j                  t               d<   | j                  |      S )Nacquire_with_timeout)timeout)typeacquireglobals)lockr   s     P/var/www/html/test/engine/venv/lib/python3.12/site-packages/gevent/_threading.pyr   r   "   s*    (,T
(:(:GI$%<<<((    c                   :    e Zd ZdZd Zd Zd Zd ZdefdZ	d Z
y	)

_Condition_lock_waitersc                      || _         g | _        y Nr   )selfr   s     r   __init__z_Condition.__init__2   s     
r   c                 6    | j                   j                         S r   )r   	__enter__r   s    r   r    z_Condition.__enter__=   s    zz##%%r   c                 <    | j                   j                  |||      S r   )r   __exit__)r   tvtbs       r   r#   z_Condition.__exit__@   s    zz""1a,,r   c                 J    d| j                   t        | j                        fz  S )Nz<Condition(%s, %d)>)r   lenr   r!   s    r   __repr__z_Condition.__repr__C   s    $

C4F'GGGr   c                    d}|j                          | j                  j                  |       | j                  j	                          	  |||      }| j                  j                          |s|j                  d      }|s-| j                  j                  |       |j	                          |S |j	                          |S # | j                  j                          w xY w)NTF)r   r   appendr   releaseremove)r   	wait_lockr   _wait_for_notifygevent_threadpool_worker_idlenotifieds         r   waitz_Condition.waitF   s     )-%
 	Y'

	! (	7;HJJ  
 !((/HMM  +   ' JJ s   		C   Cc                 x    	 | j                   j                         }|j                          y # t        $ r Y y w xY wr   )r   popr-   
IndexError)r   waiters     r   
notify_onez_Condition.notify_onem   s9    		]]&&(F NN  		s   - 	99N)__name__
__module____qualname__	__slots__r   r    r#   r)   r   r3   r8    r   r   r   r   '   s1    I
&-H ');O %Nr   r   c                       e Zd ZdZy)r	   zERaised from :meth:`Queue.get` if no item is available in the timeout.N)r9   r:   r;   __doc__r=   r   r   r	   r	   z   s    Or   r	   c                   P    e Zd ZdZdZd Zd ZefdZd Z	d Z
d Zdd	Zd
 Zd Zy)r   zH
    Create a queue object.

    The queue is always infinite size.
    _queue_mutex
_not_emptyunfinished_tasksc                     t               | _        t               | _        t	        | j                        | _        d| _        y )Nr   )r   rB   r   rC   r   rD   rE   r!   s    r   r   zQueue.__init__   s0    g
 f %T[[1 !r   c                     | j                   5  | j                  dz
  }|dk  r|dk  rt        d| j                  z        || _        ddd       y# 1 sw Y   yxY w)a.  Indicate that a formerly enqueued task is complete.

        Used by Queue consumer threads.  For each get() used to fetch a task,
        a subsequent call to task_done() tells the queue that the processing
        on the task is complete.

        If a join() is currently blocking, it will resume when all items
        have been processed (meaning that a task_done() call was received
        for every item that had been put() into the queue).

        Raises a ValueError if called more times than there were items
        placed in the queue.
           r   z5task_done() called too many times; %s remaining tasksN)rC   rE   
ValueError)r   
unfinisheds     r   	task_donezQueue.task_done   sf     [[ 		/..2JQ>$O 11 
 %/D!		/ 		/ 		/s   9AAc                 &     || j                         S )z9Return the approximate size of the queue (not reliable!).)rB   )r   r(   s     r   qsizezQueue.qsize   s    4;;r   c                 $    | j                          S )zCReturn True if the queue is empty, False otherwise (not reliable!).)rM   r!   s    r   emptyzQueue.empty   s    ::<r   c                      y)zBReturn True if the queue is full, False otherwise (not reliable!).Fr=   r!   s    r   fullz
Queue.full   s    r   c                     | j                   5  | j                  j                  |       | xj                  dz  c_        | j                  j                          ddd       y# 1 sw Y   yxY w)z$Put an item into the queue.
        rH   N)rC   rB   r,   rE   rD   r8   )r   items     r   putz	Queue.put   sS     [[ 	)KKt$!!Q&!OO&&(	) 	) 	)s   AA!!A*c                    | j                   5  | j                  s=| j                  j                  ||      }|s| j                  st        | j                  s=| j                  j                         }|cddd       S # 1 sw Y   yxY w)a"  
        Remove and return an item from the queue.

        If *timeout* is given, and is not -1, then we will
        attempt to wait for only that many seconds to get an item.
        If those seconds elapse and no item has become available,
        raises :class:`EmptyTimeout`.
        N)rC   rB   rD   r3   r	   popleft)r   cookier   r2   rS   s        r   getz	Queue.get   sp     [[ 	kk  ??//@  && kk ;;&&(D	 	 	s   A	A<A<<Bc                     t               S )z
        Create and return the *cookie* to pass to `get()`.

        Each thread that will use `get` needs a distinct cookie.
        )r   r!   s    r   allocate_cookiezQueue.allocate_cookie   s     vr   c                 <    d| _         d| _        d| _        d| _        y)z
        Call to destroy this object.

        Use this when it's not possible to safely drain the queue, e.g.,
        after a fork when the locks are in an uncertain state.
        NrA   r!   s    r   killz
Queue.kill   s!      $r   Nr*   )r9   r:   r;   r?   r<   r   rK   r(   rM   rO   rQ   rT   rX   rZ   r\   r=   r   r   r   r   ~   sA     GI"/2    ).
%r   r   Nr]   )r?   
__future__r   collectionsr   geventr   gevent._compatr   __all__get_originalr
   r   get_thread_identr   objectr   	Exceptionr	   r   r=   r   r   <module>rg      su   
 '   * -@F,?,? R - ) $()
Q QfP9 Pl%F l%r   