o
    i	                     @   sf   d dl Z d dlZd dlZeeZzd dlZW n ey$   d dlZY nw d dl	Z	G dd de
ZdS )    Nc                   @   sd   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )	TaskQueuec                 C   s6   || _ || _g | _t | _t | _d | _	d| _
d S )N )_TaskQueue__producer_TaskQueue__consumers_TaskQueue__threadsqueueQueue_TaskQueue__queue	threadingLock_TaskQueue__lock_TaskQueue__exc_info_TaskQueue__exc_stack)selfproducer	consumers r   C/home/ubuntu/.local/lib/python3.10/site-packages/oss2/task_queue.py__init__   s   


zTaskQueue.__init__c                 C   s   |  tj| jd | jD ]}|  tj| j|fd q|  r/| jD ]}|d q#|  s | j	r@t
d| j | j	d d S )N)target)r   args   z?An exception was thrown by producer or consumer, backtrace: {0})_TaskQueue__add_and_runr
   Thread_TaskQueue__producer_funcr   _TaskQueue__consumer_func_TaskQueue__any_activer   joinr   loggererrorformatr   )r   ctr   r   r   run   s   


zTaskQueue.runc                 C   s   |d usJ | j | d S N)r	   put)r   datar   r   r   r%   .   s   zTaskQueue.putc                 C   s
   | j  S r$   )r	   getr   r   r   r   r'   2   s   
zTaskQueue.getc                 C   s4   | j  | jd u W  d    S 1 sw   Y  d S r$   )r   r   r(   r   r   r   ok5   s   $zTaskQueue.okc                 C   s   d|_ |  | j| d S )NT)daemonstartr   append)r   threadr   r   r   __add_and_run9   s   zTaskQueue.__add_and_runc                 C   s   t dd | jD S )Nc                 s   s    | ]}|  V  qd S r$   )is_alive).0r"   r   r   r   	<genexpr>?   s    z)TaskQueue.__any_active.<locals>.<genexpr>)anyr   r(   r   r   r   __any_active>   s   zTaskQueue.__any_activec                 C   s>   z|  |  W n   | t  |   Y d S |   d S r$   )r   _TaskQueue__on_exceptionsysexc_info_TaskQueue__put_endr(   r   r   r   __producer_funcA   s   zTaskQueue.__producer_funcc                 C   s*   z||  W d S    |  t  Y d S r$   )r4   r5   r6   )r   consumerr   r   r   __consumer_funcJ   s   zTaskQueue.__consumer_funcc                 C   s$   t t| jD ]}| jd  qd S r$   )rangelenr   r	   r%   )r   ir   r   r   	__put_endP   s   zTaskQueue.__put_endc                 C   sV   | j  | jd u r|| _t | _W d    d S W d    d S 1 s$w   Y  d S r$   )r   r   	traceback
format_excr   )r   r6   r   r   r   __on_exceptionT   s   
"zTaskQueue.__on_exceptionN)__name__
__module____qualname__r   r#   r%   r'   r)   r   r   r   r   r7   r4   r   r   r   r   r      s    	r   )r
   r5   logging	getLoggerrB   r   r   r   ImportErrorr?   objectr   r   r   r   r   <module>   s   
