o
    0׾g                      @   s   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
eg d\ZZZdd	d
ZG dd deZG dd deZG d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                 C   s   t | jt d< | j|dS )Nacquire_with_timeout)timeout)typeacquireglobals)lockr    r   [/var/www/html/backend_erp/backend_erp_env/lib/python3.10/site-packages/gevent/_threading.pyr   "   s   r   c                   @   sF   e Zd ZdZdd Zdd Zdd Zdd	 Zd
efddZ	dd Z
dS )
_Condition_lock_waitersc                 C   s   || _ g | _d S Nr   )selfr   r   r   r   __init__2   s   
z_Condition.__init__c                 C   s
   | j  S r   )r   	__enter__r   r   r   r   r   =   s   
z_Condition.__enter__c                 C   s   | j |||S r   )r   __exit__)r   tvtbr   r   r   r   @   s   z_Condition.__exit__c                 C   s   d| j t| jf S )Nz<Condition(%s, %d)>)r   lenr   r   r   r   r   __repr__C   s   z_Condition.__repr__r   c                 C   s~   d}|   | j| | j  z|||}W | j   n| j   w |s+| d}|s9| j| |  |S |  |S )NTF)r   r   appendr   releaseremove)r   	wait_lockr   _wait_for_notifygevent_threadpool_worker_idlenotifiedr   r   r   waitF   s   

z_Condition.waitc                 C   s0   z| j  }W n
 ty   Y d S w |  d S r   )r   pop
IndexErrorr%   )r   waiterr   r   r   
notify_onem   s   z_Condition.notify_oneN)__name__
__module____qualname__	__slots__r   r   r   r#   r   r+   r/   r   r   r   r   r   '   s    'r   c                   @   s   e Zd ZdZdS )r   zERaised from :meth:`Queue.get` if no item is available in the timeout.N)r0   r1   r2   __doc__r   r   r   r   r   z   s    r   c                   @   sb   e Zd ZdZdZdd Zdd ZefddZd	d
 Z	dd Z
dd ZdddZdd Zdd ZdS )r   zH
    Create a queue object.

    The queue is always infinite size.
    _queue_mutex
_not_emptyunfinished_tasksc                 C   s&   t  | _t | _t| j| _d| _d S )Nr   )r   r6   r   r7   r   r8   r9   r   r   r   r   r      s   
zQueue.__init__c                 C   sZ   | j   | jd }|dkr|dk rtd| j || _W d   dS 1 s&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)r7   r9   
ValueError)r   
unfinishedr   r   r   	task_done   s   
"zQueue.task_donec                 C   s
   || j S )z9Return the approximate size of the queue (not reliable!).)r6   )r   r"   r   r   r   qsize      
zQueue.qsizec                 C   s
   |    S )zCReturn True if the queue is empty, False otherwise (not reliable!).)r>   r   r   r   r   empty   r?   zQueue.emptyc                 C   s   dS )zBReturn True if the queue is full, False otherwise (not reliable!).Fr   r   r   r   r   full   s   z
Queue.fullc                 C   sP   | j  | j| |  jd7  _| j  W d   dS 1 s!w   Y  dS )z$Put an item into the queue.
        r:   N)r7   r6   r$   r9   r8   r/   )r   itemr   r   r   put   s
   "z	Queue.putr   c                 C   s`   | j # | js| j||}|s| jst| jr| j }|W  d   S 1 s)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)r7   r6   r8   r+   r   popleft)r   cookier   r*   rB   r   r   r   get   s   	


$z	Queue.getc                 C   s   t  S )z
        Create and return the *cookie* to pass to `get()`.

        Each thread that will use `get` needs a distinct cookie.
        )r   r   r   r   r   allocate_cookie   s   zQueue.allocate_cookiec                 C   s   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.
        Nr5   r   r   r   r   kill   s   
z
Queue.killNr   )r0   r1   r2   r4   r3   r   r=   r"   r>   r@   rA   rC   rF   rG   rH   r   r   r   r   r   ~   s    
r   NrI   )r4   
__future__r   collectionsr   geventr   gevent._compatr   __all__get_originalr	   r   get_thread_identr   objectr   	Exceptionr   r   r   r   r   r   <module>   s    
S