
    i                          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dS )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                 t    t          |           j        t                      d<   |                     |          S )Nacquire_with_timeout)timeout)typeacquireglobals)lockr   s     </usr/local/lib/python3.11/dist-packages/gevent/_threading.pyr   r   "   s.    (,T

(:GII$%<<<(((    c                   <    e Zd ZdZd Zd Zd Zd ZdefdZ	d Z
d	S )

_Condition_lock_waitersc                 "    || _         g | _        d S Nr   )selfr   s     r   __init__z_Condition.__init__2   s     
r   c                 4    | j                                         S r   )r   	__enter__r   s    r   r!   z_Condition.__enter__=   s    z##%%%r   c                 :    | j                             |||          S r   )r   __exit__)r   tvtbs       r   r$   z_Condition.__exit__@   s    z""1a,,,r   c                 >    d| j         t          | j                  fz  S )Nz<Condition(%s, %d)>)r   lenr   r"   s    r   __repr__z_Condition.__repr__C   s    $
C4F4F'GGGr   r   c                    d}|                                  | j                            |           | j                                         	  |||          }| j                                          n# | j                                          w xY w|s|                     d          }|s/| j                            |           |                                 n|                                 |S )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J    DJ      	0
 !((//H 	 M  +++  s   A1 1Bc                     	 | j                                         }|                                 d S # t          $ r Y d S w xY wr   )r   popr-   
IndexError)r   waiters     r   
notify_onez_Condition.notify_onem   sV    		]&&((F NN  	 	 	DD	s   1 
??N)__name__
__module____qualname__	__slots__r   r!   r$   r*   r   r3   r8    r   r   r   r   '   s        I
  & & &- - -H H H ');O % % % %N    r   r   c                       e Zd ZdZdS )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        OOOOr   r	   c                   R    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dS )r   zH
    Create a queue object.

    The queue is always infinite size.
    _queue_mutex
_not_emptyunfinished_tasksc                     t                      | _        t                      | _        t	          | j                  | _        d| _        d S )Nr   )r   rB   r   rC   r   rD   rE   r"   s    r   r   zQueue.__init__   s;    gg
 ff %T[11 !r   c                     | j         5  | j        dz
  }|dk    r|dk     rt          d| j        z            || _        ddd           dS # 1 swxY w Y   dS )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   s     [ 		/ 		/.2JQ>>$O 1  
 %/D!		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/s   5A

AAc                 "     || j                   S )z9Return the approximate size of the queue (not reliable!).)rB   )r   r)   s     r   qsizezQueue.qsize   s    s4;r   c                 ,    |                                   S )zCReturn True if the queue is empty, False otherwise (not reliable!).)rM   r"   s    r   emptyzQueue.empty   s    ::<<r   c                     dS )zBReturn True if the queue is full, False otherwise (not reliable!).Fr=   r"   s    r   fullz
Queue.full   s    ur   c                     | j         5  | j                            |           | xj        dz  c_        | j                                         ddd           dS # 1 swxY w Y   dS )z$Put an item into the queue.
        rH   N)rC   rB   r,   rE   rD   r8   )r   items     r   putz	Queue.put   s     [ 	) 	)Kt$$$!!Q&!!O&&(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)s   AAA Ar   c                     | j         5  | j        s2| j                            ||          }|s| j        st          | j        2| j                                        }|cddd           S # 1 swxY w Y   dS )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   s     [ 	 	k 	'  ?//@@   ' '&& k 	' ;&&((D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA))A-0A-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     vvr   c                 >    d| _         d| _        d| _        d| _        dS )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   ~   s          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 R R - - ) $() ) ) )
Q Q Q Q Q Q Q QfP P P P P9 P P Pl% l% l% l% l%F l% l% l% l% l%r   