๓
ฆี\c           @` s   d  d l  m Z m Z m Z d d l m Z d  d l m Z d  d l m	 Z	 d  d l
 Z
 e
 j d  d e
 j d  d Z d	 e f d
     YZ d S(   i    (   t   absolute_importt   divisiont   print_functioni   (   t   Callback(   t   default_timer(   t   NumberNgฎGแzฎ๓?i   t   Cachec           B` s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s๋   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ค   y d d  l  } Wn1 t k
 rC } t d j d t |     n X| j |  _ t | t  rw | j | | |  } n | r | s t	  | |  _
 t   |  _ d  S(   Ni    s/   Cache requires cachey, "{ex}" problem importingt   ex(   t   cacheyt   ImportErrort   formatt   strt   nbytest   _nbytest
   isinstanceR   R   t   AssertionErrort   cachet   dictt
   starttimes(   t   selfR   t   argst   kwargsR   R   (    (    s)   lib/python2.7/site-packages/dask/cache.pyt   __init__    s    	c         C` sQ   t    |  _ t |  t |  j j  @} x" | D] } |  j j | | | <q/ Wd  S(   N(   R   t	   durationst   setR   t   data(   R   t   dskt   overlapt   key(    (    s)   lib/python2.7/site-packages/dask/cache.pyt   _start.   s    c         C` s   t    |  j | <d  S(   N(   R   R   (   R   R   R   t   state(    (    s)   lib/python2.7/site-packages/dask/cache.pyt   _pretask4   s    c   	      ` sง   t      j | } | d | } | rK | t   f d   | D  7} n  |   j | <  j |  t t j |  d }   j j	 | | d | | d d | d  S(   Nt   dependenciesc         3` s$   |  ] }   j  j | d   Vq d S(   i    N(   R   t   get(   t   .0t   k(   R   (    s)   lib/python2.7/site-packages/dask/cache.pys	   <genexpr>;   s    i   t   costg    eออAR   (
   R   R   t   maxR   R   t   overheadt   syst	   getsizeofR   t   put(	   R   R   t   valueR   R   t   idt   durationt   depst   nb(    (   R   s)   lib/python2.7/site-packages/dask/cache.pyt	   _posttask7   s    #$c         C` s   |  j  j   |  j j   d  S(   N(   R   t   clearR   (   R   R   R   t   errored(    (    s)   lib/python2.7/site-packages/dask/cache.pyt   _finish@   s    (   t   __name__t
   __module__t   __doc__R   R   R   R/   R2   (    (    (    s)   lib/python2.7/site-packages/dask/cache.pyR      s   					(    (   t
   __future__R    R   R   t	   callbacksR   t   timeitR   t   numbersR   R'   R(   R&   R   (    (    (    s)   lib/python2.7/site-packages/dask/cache.pyt   <module>   s   $