o
    ˆì_cs  ã                   @   s`   d dl Z d dlmZmZmZ d dlmZ d dlmZ ddgZG dd„ de	ƒZ
G dd„ deƒZdS )	é    N)ÚEventÚThreadÚcurrent_thread)Útime)ÚwarnÚTMonitorÚTqdmSynchronisationWarningc                   @   s   e Zd ZdZdS )r   zhtqdm multi-thread/-process errors which may cause incorrect nesting
    but otherwise no adverse effectsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   ú8/usr/local/lib/python3.10/dist-packages/tqdm/_monitor.pyr   	   s    c                   @   s<   e Zd ZdZi Zdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Z	dS )r   a^  
    Monitoring thread for tqdm bars.
    Monitors if tqdm bars are taking too much time to display
    and readjusts miniters automatically if necessary.

    Parameters
    ----------
    tqdm_cls  : class
        tqdm class to use (can be core tqdm or a submodule).
    sleep_interval  : float
        Time to sleep between monitoring checks.
    c                 C   s\   t  | ¡ d| _d| _|| _|| _| j dt¡| _	| j dt
¡ƒ | _t | j¡ |  ¡  d S )NTr   r   r   )r   Ú__init__ÚdaemonÚwokenÚtqdm_clsÚsleep_intervalÚ_testÚgetr   Ú_timer   Ú
was_killedÚatexitÚregisterÚexitÚstart)Úselfr   r   r   r   r   r      s   
zTMonitor.__init__c                 C   s$   | j  ¡  | tƒ ur|  ¡  |  ¡ S ©N)r   Úsetr   ÚjoinÚreport©r   r   r   r   r   )   s   

zTMonitor.exitc                 C   s   dd„ | j j ¡ D ƒS )Nc                 S   s   g | ]	}t |d ƒr|‘qS )Zstart_t)Úhasattr)Ú.0Úir   r   r   Ú
<listcomp>1   s    
þz*TMonitor.get_instances.<locals>.<listcomp>)r   Z
_instancesÚcopyr!   r   r   r   Úget_instances/   s   zTMonitor.get_instancesc                 C   sØ   |   ¡ }	 || _| j | j¡ | j ¡ rd S | j ¡ H |   ¡ }|  ¡ }|D ]'}| j ¡ r6 W d   ƒ d S |j	dkrL||j
 |jkrLd|_	|jdd ~q&||  ¡ kr[tdtdd ~W d   ƒ n1 sfw   Y  q)NTé   )ZnolockzOSet changed size during iteration (see https://github.com/tqdm/tqdm/issues/481)é   )Ú
stacklevel)r   r   r   Úwaitr   Úis_setr   Zget_lockr'   ZminitersZlast_print_tZmaxintervalÚrefreshr   r   )r   Zcur_tZ	instancesÚinstancer   r   r   Úrun5   s6   

ùÿþþæõzTMonitor.runc                 C   s   | j  ¡  S r   )r   r,   r!   r   r   r   r    ^   s   zTMonitor.reportN)
r	   r
   r   r   r   r   r   r'   r/   r    r   r   r   r   r      s    ))r   Ú	threadingr   r   r   r   Úwarningsr   Ú__all__ÚRuntimeWarningr   r   r   r   r   r   Ú<module>   s    