U
    a¨+ds  ã                   @   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   ú1/tmp/pip-unpacked-wheel-tf4cttdx/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ƒ k	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 ¡ „ |   ¡ }|  ¡ }|D ]L}| j ¡ rh W 5 Q R £ d S |j	dkr”||j
 |jkr”d|_	|jdd ~qJ||  ¡ kr²tdtdd ~W 5 Q R X qd S )Né   T)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maxintervalZrefreshr   r   )r   Zcur_tZ	instancesÚinstancer   r   r   Úrun5   s0    

ÿþ þ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   