
    >ie                        d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ  edd          d	             Z G d
 de	          ZdS )    )annotationsN)default_timer)Callback)_deprecatedz2022.6.0zdask.utils.format_time)after_versionuse_insteadc                    t          | d          \  }}t          |d          \  }}|r|dd|dd|ddS |r
|dd|ddS |ddS )zFormat seconds into a human readable form.

    >>> format_time(10.4)  # doctest: +SKIP
    '10.4s'
    >>> format_time(1000.4)  # doctest: +SKIP
    '16min 40.4s'
    <   z2.0fzhr zmin z4.1fs)divmod)tmr   hs       9lib/python3.11/site-packages/dask/diagnostics/progress.pyformat_timer      s     !R==DAq!R==DAq 222Q22222222	
 '''a'''''||||    c                  >    e Zd ZdZddZd Zd Zd	 Zd
 Zd Z	d Z
dS )ProgressBara%  A progress bar for dask.

    Parameters
    ----------
    minimum : int, optional
        Minimum time threshold in seconds before displaying a progress bar.
        Default is 0 (always display)
    width : int, optional
        Width of the bar
    dt : float, optional
        Update resolution in seconds, default is 0.1 seconds
    out : file object, optional
        File object to which the progress bar will be written
        It can be ``sys.stdout``, ``sys.stderr`` or any other file object able to write ``str`` objects
        Default is ``sys.stdout``

    Examples
    --------

    Below we create a progress bar with a minimum threshold of 1 second before
    displaying. For cheap computations nothing is shown:

    >>> with ProgressBar(minimum=1.0):      # doctest: +SKIP
    ...     out = some_fast_computation.compute()

    But for expensive computations a full progress bar is displayed:

    >>> with ProgressBar(minimum=1.0):      # doctest: +SKIP
    ...     out = some_slow_computation.compute()
    [########################################] | 100% Completed | 10.4 s

    The duration of the last computation is available as an attribute

    >>> pbar = ProgressBar()                # doctest: +SKIP
    >>> with pbar:                          # doctest: +SKIP
    ...     out = some_computation.compute()
    [########################################] | 100% Completed | 10.4 s
    >>> pbar.last_duration                  # doctest: +SKIP
    10.4

    You can also register a progress bar so that it displays for all
    computations:

    >>> pbar = ProgressBar()                # doctest: +SKIP
    >>> pbar.register()                     # doctest: +SKIP
    >>> some_slow_computation.compute()     # doctest: +SKIP
    [########################################] | 100% Completed | 10.4 s
    r   (   皙?Nc                h    |t           j        }|| _        || _        || _        || _        d| _        d S )Nr   )sysstdout_minimum_width_dt_filelast_duration)selfminimumwidthdtouts        r   __init__zProgressBar.__init__R   s:    ; *C
r   c                    d | _         t                      | _        d| _        t	          j        | j                  | _        d| j        _        | j        	                                 d S )NT)target)
_stater   _start_time_running	threadingThread_timer_func_timerdaemonstart)r   dsks     r   _startzProgressBar._start^   sX    (??&d.>???!r   c                X    || _         | j        | j                                         d S d S N)r'   r   flush)r   keyr0   states       r   _pretaskzProgressBar._pretaskg   s3    :!J "!r   c                n   d| _         | j                                         t                      | j        z
  }|| _        || j        k     rd S |s|                     d|           n|                     |           | j	        5| j	        
                    d           | j	                                         d S d S )NF   
)r)   r-   joinr   r(   r   r   	_draw_bar_update_barr   writer4   )r   r0   r6   erroredelapseds        r   _finishzProgressBar._finishl   s    //D$44$T]""F 	&NN1g&&&&W%%%:!JT"""J "!r   c                    | j         rXt                      | j        z
  }|| j        k    r|                     |           t          j        | j                   | j         VdS dS )z/Background thread for updating the progress barN)r)   r   r(   r   r=   timesleepr   )r   r@   s     r   r,   zProgressBar._timer_func{   sp    m 	!#oo(88G&&  )))Jtx   	 m 	! 	! 	! 	! 	!r   c                    | j         s|                     d|           d S t          d                   }t          fddD                       |z   }||k     r|                     |r||z  nd|           d S d S )Nr   finishedc              3  B   K   | ]}t          |                   V  d S r3   )len).0kr   s     r   	<genexpr>z*ProgressBar._update_bar.<locals>.<genexpr>   s-      HH1S1YYHHHHHHr   )readywaitingrunning)r'   r<   rH   sum)r   r@   ndonentasksr   s       @r   r=   zProgressBar._update_bar   s    K 	NN1g&&&FAjM""HHHH(GHHHHH5P6>>NNV:56>>GDDDDD >r   c                   ddl m} dt          | j        |z            z  }t          d|z            } ||          }d                    || j        ||          }t          j        t                    5  | j        3| j        	                    |           | j        
                                 d d d            d S # 1 swxY w Y   d S )Nr   )r   #d   z"[{0:<{1}}] | {2}% Completed | {3})
dask.utilsr   intr   format
contextlibsuppress
ValueErrorr   r>   r4   )r   fracr@   r   barpercentmsgs          r   r<   zProgressBar._draw_bar   s   ******Cd*+++cDj//+g&&3::gw
 
  ,, 	# 	#z%
  %%%
  """	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s   4;B<<C C )r   r   r   N)__name__
__module____qualname____doc__r$   r1   r7   rA   r,   r=   r<    r   r   r   r       s        / /b
 
 
 
    
  ! ! !E E E# # # # #r   r   )
__future__r   rX   r   r*   rC   timeitr   dask.callbacksr   rU   r   r   r   rc   r   r   <module>rg      s    " " " " " "     



                  # # # # # # " " " " " " :3KLLL  ML$y# y# y# y# y#( y# y# y# y# y#r   