o
    Nrf                     @  sh   d dl mZ d dlZd dlmZ d dlmZ d dlmZ e	dd e	dd  Z
G d	d
 d
eZdS )    )annotationsN)Number)default_timer)CallbackgGz?    c                   @  s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )Cachea  Use cache for computation

    Examples
    --------

    >>> cache = Cache(1e9)  # doctest: +SKIP

    The cache can be used locally as a context manager around ``compute`` or
    ``get`` calls:

    >>> with cache:  # doctest: +SKIP
    ...     result = x.compute()

    You can also register a cache globally, so that it works for all
    computations:

    >>> cache.register()    # doctest: +SKIP
    >>> cache.unregister()  # doctest: +SKIP
    c              
   O  s   zdd l }W n ty } ztdt| d|d }~ww |j| _t|tr4|j|g|R i |}n|s8|r:J || _t	 | _
d S )Nr   zCache requires cachey, "z" problem importing)cacheyImportErrorstrnbytes_nbytes
isinstancer   r   cachedict
starttimes)selfr   argskwargsr	   exr   r   S/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/dask/cache.py__init__!   s    
zCache.__init__c                 C  s:   t  | _t|t| jj@ }|D ]
}| jj| ||< qd S N)r   	durationssetr   data)r   dskoverlapkeyr   r   r   _start0   s
   zCache._startc                 C  s   t  | j|< d S r   )r   r   )r   r   r   stater   r   r   _pretask6   s   zCache._pretaskc           	        s   t   j|  }|d | }|r|t fdd|D 7 }| j|<  |t t|d  } jj	|||| d |d d S )Ndependenciesc                 3  s    | ]
} j |d V  qdS )r   N)r   get).0kr   r   r   	<genexpr>=   s    z"Cache._posttask.<locals>.<genexpr>r   g    eA)Zcostr   )
r   r   maxr   r   overheadsys	getsizeofr   put)	r   r   valuer   r    iddurationdepsnbr   r&   r   	_posttask9   s   
 zCache._posttaskc                 C  s   | j   | j  d S r   )r   clearr   )r   r   r    Zerroredr   r   r   _finishB   s   
zCache._finishN)	__name__
__module____qualname____doc__r   r   r!   r2   r4   r   r   r   r   r      s    	r   )
__future__r   r*   numbersr   Ztimeitr   Zdask.callbacksr   r+   r)   r   r   r   r   r   <module>   s    