3
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   -/tmp/pip-build-v9q4h5k9/tqdm/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 j|  d| _d| _|| _|| _| jjdt| _	| jjdt
 | _tj| j | 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 j  | t k	r| j  | j S )N)r   setr   joinreport)r   r   r   r   r   )   s    

zTMonitor.exitc             C   s   dd | j 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copy)r   r   r   r   get_instances/   s    zTMonitor.get_instancesc             C   s   | j  }x|| _| jj| j | jj r,d S | jj | | j  }| j }xH|D ]@}| jj r`d S |j	dkr||j
 |jkrd|_	|jdd ~qNW || j krtdtdd ~W d Q R X q
W d S )	N   T)Znolockz!Set changed size during iterationz. (see https://github.com/tqdm/tqdm/issues/481)   )
stacklevelzOSet changed size during iteration (see https://github.com/tqdm/tqdm/issues/481))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   s,    




zTMonitor.runc             C   s   | j j  S )N)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   