
\c           @` sf  d  d l  m Z m Z m Z d  d l Z d  d l m Z d  d l m Z d  d l	 m
 Z
 m Z d  d l m Z d  d l Z d  d l m Z d  d l Z d  d l m Z d  d	 l m Z d  d l Z d  d l Z d  d l Z d  d
 l m Z m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l  Z  d  d l! Z! d  d l" Z" d  d l# Z# d  d l$ m% Z% m& Z& m' Z' d  d l( m) Z) m* Z* d  d l+ m, Z, d  d l- m. Z. m/ Z/ d  d l0 m1 Z1 y, d  d l2 m3 Z3 m4 Z4 m5 Z5 m6 Z6 m7 Z7 Wn9 e8 k
 r+d  d l9 m3 Z3 m4 Z4 m5 Z5 m6 Z6 m7 Z7 n Xy d  d l: m; Z; Wn e8 k
 rYe3 Z; n Xd  d l< m= Z= d  d l> m? Z? d  d l@ mA ZA mB ZB mC ZC d  d lD mE ZE d  d lF mG ZG d d lH mI ZI d d lJ mK ZK mL ZL mM ZM mN ZN mO ZO d d lP mQ ZQ d d lR mG ZS mT ZT mU ZU mV ZV mW ZW mX ZX d d lY mZ ZZ m[ Z[ m\ Z\ m] Z] m^ Z^ d d l_ m` Z` d d la mb Zb d d lc md Zd d d  le mf Zf mg Zg d d! lh mi Zi d d" lj mk Zk d d# ll mm Zm d d$ ln mn Zn d d% lo mp Zp d d& lq mr Zr ms Zs mt Zt mu Zu d d' lv mw Zw mx Zx my Zy mz Zz m{ Z{ m| Z| m} Z} m~ Z~ m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d d( l m Z e j e  Z e" j   Z d  g Z ek g Z d)   Z d*   Z d+   Z d, eK f d-     YZ d. e f d/     YZ e= j d0    Z e e& j e  d1    Z d2 e f d3     YZ d4 eb f d5     YZ d6 e f d7     YZ d8   Z d9 Z d: Z e= j e e d;   Z e e d<  Z e= j d=    Z e= j d>    Z d? e f d@     YZ dA   Z e dB  Z dC   Z dD   Z e dE  Z dF   Z dG e f dH     YZ e dI    Z dJ   Z e j e  d S(K   i    (   t   print_functiont   divisiont   absolute_importN(   t   defaultdict(   t   ThreadPoolExecutor(   t   DoneAndNotDoneFuturest   CancelledError(   t   contextmanager(   t	   timedelta(   t   partial(   t   glob(   t   Numbert   Integral(   t   tokenizet   normalize_tokent   collections_to_dsk(   t   flattent   get_dependencies(   t   SubgraphCallable(   t   applyt   unicode(   t   ensure_dict(   t   firstt   groupbyt   merget   valmapt   keymap(   t
   single_key(   t   gen(   t   TimeoutError(   t   Eventt	   Conditiont	   Semaphore(   t   IOLoop(   t   Queuei   (   t   BatchedSend(   t
   WrappedKeyt   unpack_remotedatat	   pack_datat   scatter_to_workerst   gather_from_workers(   t   ClientExecutor(   R"   t   Emptyt   isqueuet   html_escapet   StopAsyncIterationt   Iterator(   t   connectt   rpct   clean_exceptiont   CommClosedErrort   PooledRPCCall(   t   time(   t   Node(   t   to_serialize(   t   dumpst   loads(   t   Datasets(   t   PubSubClientExtension(   t   Security(   t   sizeof(   t   rejoin(   t
   dumps_taskt
   get_clientt
   get_workert   secede(   t   Allt   synct   funcnamet   ignoringt   queue_to_iteratort   tokeyt
   log_errorst	   str_grapht	   key_splitt   format_bytest
   asciitablet   thread_statet
   no_defaultt   PeriodicCallbackt
   LoopRunnert   parse_timedeltat   shutting_downt   Any(   t   get_versionsc          C` sT   t  t t  d t }  x2 |  D]* } t | } | j d k rB | St | =q W~  d  S(   Nt   reverset   closed(   t   sortedt   listt   _global_clientst   Truet   statust   None(   t   Lt   kt   c(    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _get_global_clientk   s    
c         C` s1   |  d  k	 r- |  t t d <t d c d 7<n  d  S(   Ni    i   (   R\   RY   t   _global_client_index(   R_   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _set_global_clientw   s    c         C` sM   xF t  t  D]8 } y t | |  k r0 t | =n  Wq t k
 rD q Xq Wd  S(   N(   RX   RY   t   KeyError(   R_   R^   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _del_global_client}   s    t   Futurec           B` s%  e  Z d  Z d Z d Z d e d d  Z e d    Z	 e d    Z
 d   Z d d  Z e j e d   Z e j d    Z d d  Z d	   Z d
   Z d   Z d   Z e j d    Z d d  Z e d    Z e d  Z d   Z d   Z d   Z d   Z d   Z d   Z  RS(   s   A remotely running computation

    A Future is a local proxy to a result running on a remote worker.  A user
    manages future objects in the local Python process to determine what
    happens in the larger cluster.

    Parameters
    ----------
    key: str, or tuple
        Key of remote data to which this future refers
    client: Client
        Client that should own this future.  Defaults to _get_global_client()
    inform: bool
        Do we inform the scheduler that we need an update on this future

    Examples
    --------
    Futures typically emerge from Client computations

    >>> my_future = client.submit(add, 1, 2)  # doctest: +SKIP

    We can track the progress and results of a future

    >>> my_future  # doctest: +SKIP
    <Future: status: finished, key: add-8f6e709446674bad78ea8aeecfee188e>

    We can get the result or the exception and traceback from the future

    >>> my_future.result()  # doctest: +SKIP

    See Also
    --------
    Client:  Creates futures
    c         C` s  | |  _  t |  _ t |  } | p* t   |  _ |  j j |  |  j j |  _ | |  j j	 k rw |  j j	 | |  _
 n t   |  _
 |  j j	 | <| r |  j j i d d 6t |  g d 6|  j j d 6 n  | d  k	 ry |  j j | } Wn t k
 rqX| d |  n  d  S(   Ns   client-desires-keyst   opt   keyst   clientt   key(   Ri   t   Falset   _clearedRG   R`   Rh   t   _inc_reft
   generationt   _generationt   futurest   _statet   FutureStatet   _send_to_schedulert   idR\   t   _state_handlersRc   (   t   selfRi   Rh   t   informt   statet   tkeyt   handler(    (    s1   lib/python2.7/site-packages/distributed/client.pyt   __init__   s*    			c         C` s   |  j  S(   N(   Rh   (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   executor   s    c         C` s
   |  j  j S(   N(   Rp   R[   (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR[      s    c         C` s   |  j  j   S(   s    Is the computation complete? (   Rp   t   done(   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR|      s    c         C` s   |  j  j r% |  j  j |  j d | S|  j  j |  j d | d t } |  j d k re t j |   n |  j d k r} |  n | Sd S(   s    Wait until computation completes, gather result to local process.

        If *timeout* seconds are elapsed before returning, a
        ``dask.distributed.TimeoutError`` is raised.
        t   callback_timeoutt   raiseitt   errort	   cancelledN(   Rh   t   asynchronousRC   t   _resultRj   R[   t   sixt   reraise(   Ru   t   timeoutt   result(    (    s1   lib/python2.7/site-packages/distributed/client.pyR      s    !	c         c` s   |  j  j   V|  j d k r` t |  j  j |  j  j  } | rN t j |   q t j	 |   nh |  j d k r t
 |  j  } | r |  q t j	 |   n) |  j j |  g  V} t j	 | d   d  S(   NR   R   i    (   Rp   t   waitR[   R1   t	   exceptiont	   tracebackR   R   R   t   ReturnR   Ri   Rh   t   _gather(   Ru   R~   t   excR   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR      s    	c         c` sH   |  j  j   V|  j d k r5 t j |  j  j   n t j d    d  S(   NR   (   Rp   R   R[   R   R   R   R\   (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt
   _exception   s    c         K` s   |  j  j |  j d | | S(   s    Return the exception of a failed task

        If *timeout* seconds are elapsed before returning, a
        ``dask.distributed.TimeoutError`` is raised.

        See Also
        --------
        Future.traceback
        R}   (   Rh   RC   R   (   Ru   R   t   kwargs(    (    s1   lib/python2.7/site-packages/distributed/client.pyR     s    
c         ` s   t  } | j d k s* | j t j   k rx y t d d d | _ Wn  t k
 re t d  | _ n Xt j   | _ n    f d   } |  j j	 j
 t |  t | j j |   d S(   s-   Call callback on future when callback has finished

        The callback ``fn`` should take the future as its only argument.  This
        will be called regardless of if the future completes successfully,
        errs, or is cancelled

        The callback is executed in a separate thread.
        i   t   thread_name_prefixs   Dask-Callback-Threadc         ` s9   y   |   Wn$ t  k
 r4 t j d   |   n Xd  S(   Ns   Error in callback %s of %s:(   t   BaseExceptiont   loggerR   (   t   fut(   t   fn(    s1   lib/python2.7/site-packages/distributed/client.pyt   execute_callback#  s    N(   Re   t   _cb_executorR\   t   _cb_executor_pidt   ost   getpidR   t	   TypeErrorRh   t   loopt   add_callbackt   done_callbackR	   t   submit(   Ru   R   t   clsR   (    (   R   s1   lib/python2.7/site-packages/distributed/client.pyt   add_done_callback  s    	$c         K` s   |  j  j |  g |  S(   sd    Cancel request to run this future

        See Also
        --------
        Client.cancel
        (   Rh   t   cancel(   Ru   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR   -  s    c         K` s   |  j  j |  g |  S(   sd    Retry this future if it has failed

        See Also
        --------
        Client.retry
        (   Rh   t   retry(   Ru   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR   6  s    c         C` s   |  j  j d k S(   s/    Returns True if the future has been cancelled R   (   Rp   R[   (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR   ?  s    c         c` sH   |  j  j   V|  j d k r5 t j |  j  j   n t j d    d  S(   NR   (   Rp   R   R[   R   R   R   R\   (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt
   _tracebackC  s    c         K` s   |  j  j |  j d | | S(   s   Return the traceback of a failed task

        This returns a traceback object.  You can inspect this object using the
        ``traceback`` module.  Alternatively if you call ``future.result()``
        this traceback will accompany the raised exception.

        If *timeout* seconds are elapsed before returning, a
        ``dask.distributed.TimeoutError`` is raised.

        Examples
        --------
        >>> import traceback  # doctest: +SKIP
        >>> tb = future.traceback()  # doctest: +SKIP
        >>> traceback.format_tb(tb)  # doctest: +SKIP
        [...]

        See Also
        --------
        Future.exception
        R}   (   Rh   RC   R   (   Ru   R   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR   K  s    c         C` s
   |  j  j S(   N(   Rp   t   type(   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR   b  s    c         C` sl   |  j  rh |  j j |  j k rh t |  _  y) |  j j j |  j j t |  j	   Wqh t
 k
 rd qh Xn  d  S(   N(   Rk   Rh   Rm   Rn   RZ   R   R   t   _dec_refRG   Ri   R   (   Ru   t   _in_destructor(    (    s1   lib/python2.7/site-packages/distributed/client.pyt   releasef  s    	)c         C` s   |  j  |  j j j f S(   N(   Ri   Rh   t	   schedulert   address(   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   __getstate__p  s    c         C` sg   | \ } } t  |  } t j |  | |  | j i d d 6i  d 6t |  j  g d 6| j d 6 d  S(   Ns   update-graphRf   t   tasksRg   Rh   (   R?   Re   Rz   Rr   RG   Ri   Rs   (   Ru   Rw   Ri   R   R_   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   __setstate__s  s    c         C` s&   y |  j    Wn t k
 r! n Xd  S(   N(   R   t   RuntimeError(   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   __del__  s    c         C` sk   |  j  rS y |  j  j } Wn  t k
 r; t |  j   } n Xd |  j | |  j f Sd |  j |  j f Sd  S(   Ns'   <Future: status: %s, type: %s, key: %s>s   <Future: status: %s, key: %s>(   R   t   __name__t   AttributeErrort   strR[   Ri   (   Ru   t   typ(    (    s1   lib/python2.7/site-packages/distributed/client.pyt   __repr__  s    	c         C` s   d t  t |  j   } | d i |  j d 6|  j d k rA d n d d 67} |  j r y |  j j } Wn  t k
 r t |  j  } n X| d | 7} n  | d	 t  t |  j   7} | S(
   Ns   <b>Future: %s</b> sM   <font color="gray">status: </font><font color="%(color)s">%(status)s</font>, R[   R   t   redt   blackt   colors$   <font color="gray">type: </font>%s, s!   <font color="gray">key: </font>%s(   R,   RJ   Ri   R[   R   R   R   R   (   Ru   t   textR   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _repr_html_  s    
!	c         C` s   |  j    j   S(   N(   R   t	   __await__(   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR     s    N(!   R   t
   __module__t   __doc__R\   R   R   RZ   Rz   t   propertyR{   R[   R|   R   R   t	   coroutineR   R   R   R   R   R   R   R   R   R   Rj   R   R   R   R   R   R   R   (    (    (    s1   lib/python2.7/site-packages/distributed/client.pyRe      s4   "							
					Rq   c           B` s   e  Z d  Z d Z d   Z d   Z d   Z d d	  Z d
   Z	 d   Z
 d   Z d   Z d   Z e j d d   Z d   Z RS(   se   A Future's internal state.

    This is shared between all Futures with the same key and client.
    t   _eventR[   R   R   R   c         C` s   d  |  _ d |  _ d  |  _ d  S(   Nt   pending(   R\   R   R[   R   (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRz     s    		c         C` s,   |  j  } | d  k r( t   } |  _  n  | S(   N(   R   R\   R   (   Ru   t   event(    (    s1   lib/python2.7/site-packages/distributed/client.pyt
   _get_event  s    	c         C` s   d |  _  |  j   j   d  S(   NR   (   R[   R   t   set(   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR     s    	c         C` s5   d |  _  |  j   j   | d  k	 r1 | |  _ n  d  S(   Nt   finished(   R[   R   R   R\   R   (   Ru   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   finish  s    	c         C` s   d |  _  |  j   j   d  S(   Nt   lost(   R[   R   t   clear(   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   lose  s    	c         C` s   d |  _  |  j   j   d  S(   NR   (   R[   R   R   (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR     s    	c         C` sG   t  | |  \ } } } d |  _ | |  _ | |  _ |  j   j   d  S(   NR   (   R1   R[   R   R   R   R   (   Ru   R   R   t   _(    (    s1   lib/python2.7/site-packages/distributed/client.pyt	   set_error  s
    			c         C` s   |  j  d  k	 o |  j  j   S(   N(   R   R\   t   is_set(   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR|     s    c         C` s,   d |  _  |  j d  k	 r( |  j j   n  d  S(   NR   (   R[   R   R\   R   (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   reset  s    	c         c` s   |  j    j |  Vd  S(   N(   R   R   (   Ru   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR     s    c         C` s   d |  j  j |  j f S(   Ns   <%s: %s>(   t	   __class__R   R[   (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR     s    (   R   R[   R   R   R   N(   R   R   R   t	   __slots__Rz   R   R   R\   R   R   R   R   R|   R   R   R   R   R   (    (    (    s1   lib/python2.7/site-packages/distributed/client.pyRq     s   									c         c` s2   x! |  j  d k r# |  j j   Vq W| |   d S(   s5    Coroutine that waits on future, then calls callback R   N(   R[   Rp   R   (   t   futuret   callback(    (    s1   lib/python2.7/site-packages/distributed/client.pyR     s    c         C` s   |  j  t |   g S(   N(   Ri   R   (   t   f(    (    s1   lib/python2.7/site-packages/distributed/client.pyt   normalize_future  s    t   AllExitc           B` s   e  Z d  Z RS(   s3   Custom exception class to exit All(...) early.
    (   R   R   R   (    (    (    s1   lib/python2.7/site-packages/distributed/client.pyR     s   t   Clientc           B` s  e  Z d  Z dr dr e e dr dr e dr dr dr dr e dr d  Z e	 d    Z
 e d    Z d   Z d   Z d   Z d   Z d   Z d	   Z d
   Z e j e d   Z e j d    Z e j dr d   Z e j d    Z d   Z d   Z e j d    Z e j d    Z d   Z d   Z d   Z  d   Z! d   Z" e j d    Z# dr dr dr d  Z$ dr d  Z% dr d  Z& dr d  Z' dr dr dr d  Z( d   Z) dr d  Z* e j e d    Z+ e+ Z, e d!  Z- d"   Z. d#   Z/ d$   Z0 d%   Z1 d&   Z2 e j d' dr dr d(   Z3 e j d)    Z4 d*   Z5 d' d+ dr dr d,  Z6 e j dr e dr dr e e d-   Z7 d.   Z8 dr e dr e d+ e dr d/  Z9 e j e d0   Z: dr e d1  Z; e j d2    Z< dr d3  Z= e j d4    Z> d5   Z? d6   Z@ d7   ZA e j d8    ZB d9   ZC e j d:    ZD d;   ZE e j d<    ZF d=   ZG d>   ZH dr dr dr d+ dr dr d+ dr d?  ZI dr dr dr e dr dr dr d+ d@ dr dA 
 ZJ dB   ZK dC   ZL e e dr e dr d+ d+ d@ dr dD 	 ZM e dr dr dr dr d+ d@ dr dE  ZN e j dF    ZO dG   ZP e j e dH   ZQ dI   ZR e j e dJ   ZS e j dr dK   ZT dL   ZU e j dr dr dM   ZV dr dr dN  ZW e j dr dr dO dP   ZX dr dr dO dQ  ZY dr dR  ZZ dr dS  Z[ dr dT  Z\ dr dU  Z] dr e dV  Z^ dr dr dW  Z_ dr dr dr dr e e dr dX  Z` e j dr dr dr dr e e dr dY   Za dZ   Zb d[   Zc e d\  Zd dr d]  Ze dr dr d^  Zf dr e d_  Zg d`   Zh e g  da  Zi db   Zj dc   Zk e j dd    Zl dr e e dr de  Zm df e dr dg  Zn e	 dh    Zo e	 di    Zp dj   Zq e	 dk    Zr es dl    Zt dr dr dr e dm dn  Zu e j dr dr dr e dm do   Zv e j dr dp   Zw dr dq  Zx RS(s   ss
   Connect to and drive computation on a distributed Dask cluster

    The Client connects users to a dask.distributed compute cluster.  It
    provides an asynchronous user interface around functions and futures.  This
    class resembles executors in ``concurrent.futures`` but also allows
    ``Future`` objects within ``submit/map`` calls.

    Parameters
    ----------
    address: string, or Cluster
        This can be the address of a ``Scheduler`` server like a string
        ``'127.0.0.1:8786'`` or a cluster object like ``LocalCluster()``
    timeout: int
        Timeout duration for initial connection to the scheduler
    set_as_default: bool (True)
        Claim this scheduler as the global dask scheduler
    scheduler_file: string (optional)
        Path to a file with scheduler information if available
    security: (optional)
        Optional security information
    asynchronous: bool (False by default)
        Set to True if using this client within async/await functions or within
        Tornado gen.coroutines.  Otherwise this should remain False for normal
        use.
    name: string (optional)
        Gives the client a name that will be included in logs generated on
        the scheduler for matters relating to this client
    direct_to_workers: bool (optional)
        Whether or not to connect directly to the workers, or to ask
        the scheduler to serve as intermediary.
    heartbeat_interval: int
        Time in milliseconds between heartbeats to scheduler
    **kwargs:
        If you do not pass a scheduler address, Client will create a
        ``LocalCluster`` object, passing any extra keyword arguments.

    Examples
    --------
    Provide cluster's scheduler node address on initialization:

    >>> client = Client('127.0.0.1:8786')  # doctest: +SKIP

    Use ``submit`` method to send individual computations to the cluster

    >>> a = client.submit(add, 1, 2)  # doctest: +SKIP
    >>> b = client.submit(add, 10, 20)  # doctest: +SKIP

    Continue using submit or map on results to build up larger computations

    >>> c = client.submit(add, a, b)  # doctest: +SKIP

    Gather results with the ``gather`` method.

    >>> client.gather(c)  # doctest: +SKIP
    33

    You can also call Client with no arguments in order to create your own
    local cluster.

    >>> client = Client()  # makes your own local "cluster" # doctest: +SKIP

    Extra keywords will be passed directly to LocalCluster

    >>> client = Client(processes=False, threads_per_worker=1)  # doctest: +SKIP

    See Also
    --------
    distributed.scheduler.Scheduler: Internal scheduler
    distributed.deploy.local.LocalCluster:
    c         K` s  | t  k r! t j j d  } n  | d  k	 r? t | d  } n  | |  _ t   |  _ t	 d    |  _
 g  |  _ | d  k r t j j d d   } n  t |   j | r d | d n d t t j d t j     |  _ d |  _ d |  _ g  |  _ i  |  _ | |  _ | |  _ d  |  _ d  |  _ i  |  _ t j   |  _ t  |   |  _! |
 |  _" | d  k rf|
 } n  | |  _# | |  _$ t% d	  |  _& d  |  _' d  |  _( | pt)   |  _* d  |  _+ t, |  j* t)  st-  | d
 k r|  j* j. d
  |  _/ n |  j* j. d  |  _/ | d  k rBt j j d d   } | rBt0 j1 d |  qBn  t, | t2 t3 f  rc| |  _ n7 t4 | d  r| |  _ t5 t6   | j7 } Wd  QXn  t8 |  _9 | |  _: | |  _; t< d | d |  |  _= |  j= j7 |  _7 |	 d  k rt j j d  }	 n  t |	 d d }	 t   |  _> t? |  j@ d d |  j7 |  j> d <t? |  jA |	 d d |  j7 |  j> d <| |  _B | rt j jC d d d d  |  _D n  i |  jE d 6|  jF d 6|  jG d 6|  jH d  6|  jI d! 6|  jJ d" 6|  jK d# 6|  _L i |  jE d$ 6|  jF d% 6|  jI d& 6|  _M tN tO |   jP d' |  j/ d |  j7 d( |
 d) | d* |  x | D] } | |   qHW|  jQ d* |  d d+ lR mS } | |   d  S(,   Ns!   distributed.comm.timeouts.connectt   sc           S` s   d S(   Ni    (    (    (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   <lambda>\  t    s   client-namet   -t	   clock_seqi    s   newly-createdi   t   workerRh   s   scheduler-addresss*   Config value `scheduler-address` found: %st   scheduler_addressR   R   s   distributed.client.heartbeatt   defaultt   msi  t   io_loops   scheduler-infoi  t	   heartbeatR   s   dask.distributedt   shuffleR   s   key-in-memorys	   lost-datas   cancelled-keys   task-retrieds
   task-erredt   restartR   t   memoryR   t   erredt   connection_argst   serializerst   deserializersR   (   t   ReplayExceptionClient(T   RN   t   daskt   configt   getR\   RQ   t   _timeoutt   dictRo   R   t   refcountt
   coroutinesR   R   R   t   uuidt   uuid1R   R   Rs   Rm   R[   t   _pending_msg_buffert
   extensionst   scheduler_filet   _startup_kwargst   clusterR   t   _scheduler_identityt	   threadingt   RLockt   _refcount_lockR9   t   datasetst   _serializerst   _deserializerst   direct_to_workersR    t   _gather_semaphoret   _gather_keyst   _gather_futureR;   t   securityt   scheduler_commt
   isinstancet   AssertionErrort   get_connection_argsR   R   t   infoR0   R3   t   hasattrRE   R   R   Rj   t   _connecting_to_schedulert   _asynchronoust   _should_close_loopRP   t   _loop_runnert   _periodic_callbacksRO   t   _update_scheduler_infot
   _heartbeatt
   _start_argR   t   _set_configt   _handle_key_in_memoryt   _handle_lost_datat   _handle_cancelled_keyt   _handle_retried_keyt   _handle_task_erredt   _handle_restartt   _handle_errort   _stream_handlersRt   t   superR   Rz   t   startt   distributed.recreate_exceptionsR   (   Ru   R   R   R   t   set_as_defaultR   R   R   t   namet   heartbeat_intervalR   R   R   R   R   t   extR   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRz   D  s    		F																			
#	







		c         C` s   t    S(   s@    Return global client if one exists, otherwise raise ValueError (   t   default_client(   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   current  s    c         C` s   |  j  o |  j t j   k S(   sN   Are we running in the event loop?

        This is true if the user signaled that we might be when creating the
        client as in the following::

            client = Client(asynchronous=True)

        However, we override this expectation if we can definitively tell that
        we are running from a thread that is not the event loop.  This is
        common when calling get_client() from within a worker task.  Even
        though the client was originally created in asynchronous mode we may
        find ourselves in contexts when it is better to operate synchronously.
        (   R  R   R!   R  (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR     s    c         O` s   | j  d d   } | s3 |  j s3 t t d t  r | j  d d   } | | |   } | d  k	 r~ t j t d |  |  } n  | St	 |  j
 | | |  Sd  S(   NR   R}   t   seconds(   t   popR\   R   t   getattrRM   Rj   R   t   with_timeoutR   RC   R   (   Ru   t   funct   argsR   R   R}   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRC     s    	c         C` s   |  j  } | j d  } | rr | j d i   } t |  } t d   | j   D  } d |  j j | | | f S|  j d  k	 r d |  j j |  j j	 f Sd |  j j f Sd  S(   NR   t   workersc         s` s   |  ] } | d  Vq d S(   t   ncoresN(    (   t   .0t   w(    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>  s    s(   <%s: scheduler=%r processes=%d cores=%d>s   <%s: scheduler=%r>s   <%s: not connected>(
   R   R   t   lent   sumt   valuesR   R   R   R\   R   (   Ru   R  t   addrR&  t   nworkersR'  (    (    s1   lib/python2.7/site-packages/distributed/client.pyR     s     			c         C` s  |  j  rH t |  j  d  rH |  j  j rH |  j  j j   } |  j  j } nj |  j j   r |  j r |  j o{ |  j t j	   k r t
 |  j |  j j  } |  j } n t } |  j } | d  k	 r d | j } n d } | rd | d k r| j j d  \ } } | d d } | d k r%d } n | j d	  d
 } t j j d  } | j d | d | t j  }	 | d i |	 d 67} n  | d 7} | rt | d  }
 t d   | d j   D  } t d   | d j   D  } t |  } d |
 | | f } d | | f S| Sd  S(   NR   s0   <h3>Client</h3>
<ul>
  <li><b>Scheduler: </b>%s
s;   <h3>Client</h3>
<ul>
  <li><b>Scheduler: not connected</b>
t   bokeht   servicess   ://t   inproct	   localhostt   :i    s   distributed.dashboard.linkt   hostt   portsF     <li><b>Dashboard: </b><a href='%(web)s' target='_blank'>%(web)s</a>
t   webs   </ul>
R&  c         s` s   |  ] } | d  Vq d S(   R'  N(    (   R(  R)  (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>6  s    c         s` s   |  ] } | d  Vq d S(   t   memory_limitN(    (   R(  R)  (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>7  s    ss   <h3>Cluster</h3>
<ul>
  <li><b>Workers: </b>%d</li>
  <li><b>Cores: </b>%d</li>
  <li><b>Memory: </b>%s</li>
</ul>
s   <table style="border: 2px solid white;">
<tr>
<td style="vertical-align: top; border: 0px solid white">
%s</td>
<td style="vertical-align: top; border: 0px solid white">
%s</td>
</tr>
</table>(   R   R  R   t   identityR	  t
   is_startedR   R   R!   R  RC   Rj   R\   R   t   splitR   R   R   t   formatR   t   environR*  R+  R,  RK   (   Ru   R  R   R   t   protocolt   restR5  R4  t   templateR   R&  t   coresR   t   text2(    (    s1   lib/python2.7/site-packages/distributed/client.pyR   	  sL    				
  c         K` sk   |  j  d k r d S|  j j   t |   d |  _  |  j rQ |  j |   |  _ n t |  j |  j |  d S(   s,    Start scheduler running in separate thread s   newly-createdNt
   connecting(	   R[   R	  R  Rb   R   t   _startt   _startedRC   R   (   Ru   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR  M  s    
		c         ` sE   t    d  r   j j   St j   f d    } |   j   Sd  S(   NRD  c           ` s   t  j     d  S(   N(   R   R   (    (   Ru   (    s1   lib/python2.7/site-packages/distributed/client.pyR   a  s    (   R  RD  R   R   R   (   Ru   R   (    (   Ru   s1   lib/python2.7/site-packages/distributed/client.pyR   \  s    c         C` s{   |  j  d k rU y |  j j |  Wqw t t f k
 rQ |  j  d k rR   qR qw Xn" |  j  d k rw |  j j |  n  d  S(   Nt   runningt   closingRB  s   newly-created(   RE  RF  (   RB  s   newly-created(   R[   R   t   sendR2   R   R   t   append(   Ru   t   msg(    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _send_to_scheduler_safeg  s    c         C` sE   |  j  d k r( |  j j |  j |  n t d |  j  | f   d  S(   NRE  RF  RB  s   newly-createds<   Tried sending message after closing.  Status: %s
Message: %s(   RE  RF  RB  s   newly-created(   R[   R   R   RJ  t	   Exception(   Ru   RI  (    (    s1   lib/python2.7/site-packages/distributed/client.pyRr   q  s
    c   
      k` s  | t  k r |  j } n  | d  k	 r6 t | d  } n  |  j } |  j d  k	 r y |  j j   VWn4 t k
 rs n$ t k
 r t	 j
 d d t n X|  j j } n|  j d  k	 rWx' t j j |  j  s t j d  Vq Wxt d  D]d } y6 t |  j   } t j |  } Wd  QX| d } PWq t t f k
 rOt j d  Vq Xq Wn
|  j d  k rad d l m } y- | d	 |  j d
 t |  j  |  _ |  j VWnc t t j f k
 r} | j  t  j! k r  n  | d d d	 |  j d
 t |  j  |  _ |  j Vn XxF |  j j" s@t# |  j j$ j"  t# |  j j"  k  rQt j d  VqW|  j j } n  |  j$ d  k r|  j% |  |  _$ n  d  |  _& |  j' d |  Vx! |  j( j)   D] }	 |	 j*   qW|  j+   |  _, |  j- j. |  j,  t j/ |    d  S(   NR   s9   Tried to start cluster and received an error. Proceeding.t   exc_infog{Gz?i
   R   i   (   t   LocalClusterR   R   t   scheduler_porti    R   (0   RN   R   R\   RQ   R  R   RC  R   RK  R   R  RZ   R   R   R   t   patht   existsR   t   sleept   ranget   opent   jsont   loadt
   ValueErrorRc   t   deployRM  R   R   t   OSErrort   socketR   t   errnot
   EADDRINUSER&  R*  R   R0   R   t   _ensure_connectedR
  R,  R  t   _handle_reportt   _handle_scheduler_coroutineR   RH  R   (
   Ru   R   R   R   t   iR   t   cfgRM  t   et   pc(    (    s1   lib/python2.7/site-packages/distributed/client.pyRC  z  sl    	
	%	c      	   c` s  t    |  j j j   s" t  d |  _ d  |  _ x! |  j j   D] } | j	   qD W|  j j
   |  j } |  j j   | } x | d k r |  j d k r y |  j d |  VPWq t k
 r t j d  V| |  j j   } q Xq Wt j d |  j  |  j   VWd  QXd  S(   NRB  i    R   g?sC   Failed to reconnect to scheduler after %.2f seconds, closing client(   RH   R   t   commRV   R  R[   R\   Ro   R,  R   R   R   R   R4   R\  t   EnvironmentErrorR   RQ  R   R   t   _close(   Ru   t   stR   t   deadline(    (    s1   lib/python2.7/site-packages/distributed/client.pyt
   _reconnect  s(    
			
c         c` s  |  j  r |  j  j   s1 |  j s1 |  j d  k r5 d  St |  _ z t |  j j d | d |  j V} d | _	 | d  k	 r t
 j t d |  |  j    Vn |  j   V| j i d d 6|  j d 6t d 6 VWd  t |  _ X| d  k	 rt
 j t d |  | j    V} n | j   V} t |  d	 k s0t  | d
 d d k sJt  t d d d |  j  } | j |  | |  _  t |   d |  _ x |  j D] } |  j |  qW|  j 2t j d  d  S(   NR   R   s   Client->SchedulerR   s   register-clientRf   Rh   t   replyi   i    s   stream-startt   intervalt   10msR   RE  s+   Started scheduling coroutines. Synchronized(   R   RV   R  R   R\   RZ   R/   R   R   R  R   R#  R   R  t   writeRs   Rj   t   readR*  R  R#   R   R  Rb   R[   R   Rr   R   t   debug(   Ru   R   Rc  RI  t   bcomm(    (    s1   lib/python2.7/site-packages/distributed/client.pyR\    sB    				$
%	
	c         c` sO   |  j  d k r d  Sy |  j j   V|  _ Wn t k
 rJ t j d  n Xd  S(   NRE  RB  s(   Not able to query scheduler for identity(   RE  RB  (   R[   R   R8  R   Rd  R   Rn  (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s    c         C` s'   |  j  r# |  j  j i d d 6 n  d  S(   Ns   heartbeat-clientRf   (   R   RG  (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s    	c         C` s    |  j  j   s |  j   n  |  S(   N(   R	  R9  R  (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt	   __enter__!  s    c         c` s   |  j  Vt j |    d  S(   N(   RD  R   R   (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt
   __aenter__&  s    c         c` s   |  j    Vd  S(   N(   Re  (   Ru   R   t   valueR   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt	   __aexit__+  s    c         C` s   |  j    d  S(   N(   t   close(   Ru   R   Rr  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   __exit__/  s    c         C` s   |  j    d  S(   N(   Rt  (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR   2  s    c         C` s'   |  j   |  j | c d 7<Wd  QXd  S(   Ni   (   R   R   (   Ru   Ri   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRl   5  s    
c         C` sT   |  j  E |  j | c d 8<|  j | d k rJ |  j | =|  j |  n  Wd  QXd  S(   Ni   i    (   R   R   t   _release_key(   Ru   Ri   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR   9  s
    

c         C` s|   t  j d |  |  j j | d  } | d k	 r> | j   n  |  j d k rx |  j i d d 6| g d 6|  j d 6 n  d S(   s%    Release key from distributed memory s   Release key %sRV   s   client-releases-keysRf   Rg   Rh   N(	   R   Rn  Ro   R!  R\   R   R[   Rr   Rs   (   Ru   Ri   Rf  (    (    s1   lib/python2.7/site-packages/distributed/client.pyRv  @  s    c      
   c` s  t    yxt r|  j d k r) Pn  y |  j j j   V} WnU t k
 r |  j d k r t j	 d  t j	 d  d |  _ |  j
   Vq q Pn Xt | t t f  s | f } n  t } x | D] } t j d |  d | k rd | d k rt j t |     n  | j d  } | d	 k s5| d
 k r?t } Pn  y |  j | } | |   Wq t k
 r|} t j |  q Xq W| r Pq q WWn t k
 rn XWd QXd S(   s    Listen to scheduler RE  s(   Client report stream closed to schedulers   Reconnecting...RB  s   Client receives message %sR[   R   Rf   Rt  s   stream-closedN(   RH   RZ   R   R\   Rc  Rm  R2   R[   R   R  Rh  R  RX   t   tupleRj   Rn  R   R   R1   R!  R  RK  R   R   (   Ru   t   msgst   breakoutRI  Rf   Ry   Ra  (    (    s1   lib/python2.7/site-packages/distributed/client.pyR]  K  sF    
		c         C` su   |  j  j |  } | d  k	 rq | r[ | j r[ y t |  } Wqa t k
 rW d  } qa Xn d  } | j |  n  d  S(   N(   Ro   R   R\   R   R8   RK  R   (   Ru   Ri   R   R&  Rw   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR  x  s    c         C` s/   |  j  j |  } | d  k	 r+ | j   n  d  S(   N(   Ro   R   R\   R   (   Ru   Ri   Rw   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s    c         C` s/   |  j  j |  } | d  k	 r+ | j   n  d  S(   N(   Ro   R   R\   R   (   Ru   Ri   Rw   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s    c         C` s/   |  j  j |  } | d  k	 r+ | j   n  d  S(   N(   Ro   R   R\   R   (   Ru   Ri   Rw   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s    c         C` s5   |  j  j |  } | d  k	 r1 | j | |  n  d  S(   N(   Ro   R   R\   R   (   Ru   Ri   R   R   Rw   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s    c         C` sb   t  j d  x! |  j j   D] } | j   q W|  j j   t t   |  j j	   Wd  QXd  S(   Ns%   Receive restart signal from scheduler(
   R   R  Ro   R,  R   R   RE   R   t   _restart_eventR   (   Ru   Rw   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s    c         C` s   t  j d  t  j |  d  S(   Ns   Scheduler exception:(   R   t   warningR   (   Ru   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s    c         c` s  d |  _  t   t |   x! |  j j   D] } | j   q- Wi  |  _ t t   |  j	  Wd QXWd QX|  j
 t j j
 d d  k r t j j d =n  |  j  d k r t j    n  |  j r|  j j r|  j j j   r|  j i d d 6 |  j i d d 6 n  t t t j  + t j t d d	  |  j d
 t f VWd QX|  j r|  j j r|  j j j   r|  j j   Vn  x' t |  j  D] } |  j d |  qW|  j d k rt t   |  j j   VWd QXn  |  j  j   d |  _  t!   |  k rt" d  n  t# |  j$  } xJ |  j$ D]? } t t%   | j&   Wd QX| j'   r,| j( |  q,q,W|  j$ 2| st t  % t j t d d  t |   VWd QXn  t t   |  j) j*   Wd QXd |  _) Wd QXd |  _  d S(   s6    Send close signal and wait until scheduler completes RF  NR   RV   s   close-clientRf   s   close-streamt   millisecondsid   t   quiet_exceptionsRi   R   i   (+   R[   RH   Rd   R
  R,  t   stopR   RE   R   R  R   R   R   R\   R   R   R   Rc  RV   Rr   R   R#  R   R^  R   Rt  RX   Ro   Rv  R  R   Re  R0   R`   Rb   R   R   R   R   R   t   removeR   t	   close_rpc(   Ru   t   fastRb  Ri   R   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRe    sd    	

	
				)c         C` s   | t  k r |  j d } n  |  j d k r/ d Sd |  _ |  j ru |  j   } | rq t j t d |  |  } n  | S|  j d k r t
 t   |  j j   Wd QXn  t |  j |  j d t |  j d k s t  |  j r t   r |  j j   n  d S(   s>   Close this client

        Clients will also close automatically when your Python session ends

        If you started a client without arguments like ``Client()`` then this
        will also close the local cluster that was started at the same time.

        See Also
        --------
        Client.restart
        i   RV   NRF  R   R  (   RN   R   R[   R   Re  R   R#  R   R  R\   RE   R   R   Rt  RC   R   RZ   R  R  RR   R	  R~  (   Ru   R   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRt    s"    		c         O` s   t  j d  |  j | |   S(   s    Deprecated, see close instead

        This was deprecated because "shutdown" was sometimes confusingly
        thought to refer to the cluster rather than the client
        s1   Shutdown is deprecated.  Please use close instead(   t   warningst   warnRt  (   Ru   R%  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   shutdown  s    c         K` s   t  |  |  S(   sx  
        Return a concurrent.futures Executor for submitting tasks on this Client

        Parameters
        ----------
        **kwargs:
            Any submit()- or map()- compatible arguments, such as
            `workers` or `resources`.

        Returns
        -------
        An Executor object that's fully compatible with the concurrent.futures
        API.
        (   R)   (   Ru   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   get_executor  s    c         O` s  t  |  s t d   n  | j d d  } | j d d  } | j d d  } | j d d  } | j d d  } | j d d	  }	 | j d
 t  }
 | j d | j d t   } | j d |  } |
 t t d f k r t d   n  | d k rF| r#t |  d t | | |  } qFt |  d t t	 j
    } n  t |  } |  j ' | |  j k r~t | |  d t SWd QX|
 r| d k rt d   n  t | t j t f  r| g } n  | d k	 ri | | 6} |
 r| g n g  } n i  } g  } | r/i t | t |  | f | 6} n i | f t |  | 6} |  j | | g | | d i d | 6d | d | ri | | 6n d d | d |	 d | } t j d t |  |  | | S(   sz   Submit a function application to the scheduler

        Parameters
        ----------
        func: callable
        *args:
        **kwargs:
        pure: bool (defaults to True)
            Whether or not the function is pure.  Set ``pure=False`` for
            impure functions like ``np.random.random``.
        workers: set, iterable of sets
            A set of worker hostnames on which computations may be performed.
            Leave empty to default to all workers (common case)
        key: str
            Unique identifier for the task.  Defaults to function-name and hash
        allow_other_workers: bool (defaults to False)
            Used with `workers`. Indicates whether or not the computations
            may be performed on workers that are not in the `workers` set(s).
        retries: int (default to 0)
            Number of allowed automatic retries if the task fails
        priority: Number
            Optional prioritization of task.  Zero is default.
            Higher priorities take precedence
        fifo_timeout: str timedelta (default '100ms')
            Allowed amount of time between calls to consider the same priority

        Examples
        --------
        >>> c = client.submit(add, a, b)  # doctest: +SKIP

        Returns
        -------
        Future

        See Also
        --------
        Client.map: Submit on many arguments at once
        s1   First input to submit must be a callable functionRi   R&  t	   resourcest   retriest   priorityi    t   fifo_timeoutt   100mst   allow_other_workerst   actort   actorst   pures*   allow_other_workers= must be True or FalseR   Rv   Ns/   Only use allow_other_workers= if using workers=t   user_prioritys   Submit %s(...), %s(   t   callableR   R!  R\   Rj   RZ   RD   R   R   R   t   uuid4RG   R   Ro   Re   RV  R  R   t   string_typesR   R   RX   Rw  t   _graph_to_futuresR   Rn  (   Ru   R$  R%  R   Ri   R&  R  R  R  R  R  R  R  t   skeyt   restrictionst   loose_restrictionst   dskRo   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR   +  s\    '##
"	c   
      K` s   t  | d  r t j } n% t | d t  r8 t } n	 t    xs t r y# g  | D] } | |  ^ qT } Wn! t k
 r } | j	 |  Pn X|  j
 | | |  }	 | j	 |	  qD Wd S(   s%    Internal function for mapping Queue i    N(   R+   t   pyQueueR   R  R.   t   nextt   NotImplementedErrorRZ   t   StopIterationt   putR   (
   Ru   t   q_outR$  t   qs_inR   R   t   qR%  Ra  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _threaded_map  s    			#c         ` s7  t     s t d   n  t t t |   sF t d   | D  r | j d d  } t d |  } t j d |  j	 d d d |   | f d	 |  } t
 | _ | j   t | d  r | St |  Sn  | j d
 d!  } | p t    } | j d d!   | j d d!  } | j d d!   | j d d  }	 | j d t  }
 | j d d  } | j d | j d t   } | j d |  } |
 r d! k rt d   n  t t t |      } t | t  r| } n | rg  t |   D]  } | d t   | |  ^ q} nb t t j    } | rug  t t t t |    D]( } | d | d t |  ^ qMn g  } | s  f d   t | t |    D } n i   i  } xe | j   D]W \ } } t |  d k rt j |  } | j   | <| j! | j  q|  | <qW| j!    f d   t | t |    D  t  t" j# t$ f  rq g  n  t  t t% f  r rt t&   t t% f  rt   t |  k rt d t   t |  f   n  t' t |    } q6 f d   | D } n!  d! k r*i  } n t d   |
 t
 t d! f k rZt d   n  |
 t
 k rut% |  } n	 t%   } t' t | t t |     }  r f d   | D  n d!  |  j( | | | | d | d  d | d |	 d | d | } t) j* d  t     g  | D] } | t+ |  ^ qS("   s   Map a function on a sequence of arguments

        Arguments can be normal objects or Futures

        Parameters
        ----------
        func: callable
        iterables: Iterables, Iterators, or Queues
        key: str, list
            Prefix for task names if string.  Explicit names if list.
        pure: bool (defaults to True)
            Whether or not the function is pure.  Set ``pure=False`` for
            impure functions like ``np.random.random``.
        workers: set, iterable of sets
            A set of worker hostnames on which computations may be performed.
            Leave empty to default to all workers (common case)
        retries: int (default to 0)
            Number of allowed automatic retries if a task fails
        priority: Number
            Optional prioritization of task.  Zero is default.
            Higher priorities take precedence
        fifo_timeout: str timedelta (default '100ms')
            Allowed amount of time between calls to consider the same priority
        **kwargs: dict
            Extra keywords to send to the function.
            Large values will be included explicitly in the task graph.

        Examples
        --------
        >>> L = client.map(func, sequence)  # doctest: +SKIP

        Returns
        -------
        List, iterator, or Queue of futures, depending on the type of the
        inputs.

        See also
        --------
        Client.submit: Submit a single function
        s.   First input to map must be a callable functionc         s` s   |  ] } t  | t  Vq d  S(   N(   R  R.   (   R(  R_  (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>  s    t   maxsizei    t   targetR  s   Threaded map()R%  R   Ri   R&  R  R  R  R  R  R  R  R  R  s/   Only use allow_other_workers= if using workers=R   c         ` s&   i  |  ] \ } }   f | |  q S(    (    (   R(  Ri   R%  (   R$  (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>  s   	 g     j@c         ` s7   i  |  ]- \ } } t    t t |  f  f |  q S(    (   R   Rw  RX   (   R(  Ri   R%  (   R$  t   kwargs2(    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>  s   	sD   You only provided %d worker restrictions for a sequence of length %dc         ` s   i  |  ] }   |  q S(    (    (   R(  R^   (   R&  (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>   s   	 s0   Workers must be a list or set of workers or Nones*   allow_other_workers= must be True or Falsec         ` s   i  |  ] }   |  q S(    (    (   R(  R^   (   R  (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>/  s   	 R  s   map(%s, ...)N(,   R  R   t   allt   mapR+   R!  R  R   t   ThreadR  RZ   t   daemonR  RF   R\   RD   Rj   RV  RX   t   zipR  R   R   R   R  RR  t   minR*  t   itemsR<   R   t   delayedt   _keyt   updateR   R  R   R   R   R   R  R   Rn  RG   (   Ru   R$  t	   iterablesR   R  R  t   tRi   R  R  R  R  R  R  Rg   R%  t   uidR_  R  R^   t   vt   vvR  R  R  Ro   (    (   R$  R  R  R&  s1   lib/python2.7/site-packages/distributed/client.pyR    s    )				
	3J(!		!	t   raisec      	   #` s  t  | d t \ } } g  | D] } t | j  ^ q } t   }	 i  }
 | d  k ra  j } n  | d  k r y t   } Wn t k
 r t	 } q X| j
 j  j
 j k r t } q n  t j    f d    } x&t rt j d  t t  > t g  | D]! } |  j k r | |  ^ q d t VWd  QXd } t   } t   } x | D] } |  j k s j | j | k rT| j |    d k r
y#  j | } | j } | j } Wn0 t t f k
 rt j t t |  d   q
Xt j t |  | |  n    d k r0| j |  d  |	 | <qCt d	     qTqTWg  | D]$ } | | k rN| |
 k rN| ^ qN}  r|
 j   f d
   | D  g  | D] } | |
 k r| ^ q} n   j! r j" t |  O_"  j! V} nL t |   _"  j# |   }  j" d  k r*d   _! n	 |  _! | V} | d d k r  d k r_t j$ n t j } | d t% | d  | d  x- | d D]! }  j& i d d 6| d 6 qWx? | d D]/ } y  j | j'   Wqt k
 rqXqWq Pq W|	 rE  d k rEt( | t)  rEg  | D] } | |	 k r$| ^ q$} n  |
 j  | d  t* | t+ |
 |	   } t j, |   d  S(   Nt	   byte_keysc         3` sC    j  |  } | j   V| j d k r?   d k r? t    n  d S(   s5    Want to stop the All(...) early if we find an error R   R  N(   Ro   R   R[   R   (   R^   Rf  (   t   errorsRu   (    s1   lib/python2.7/site-packages/distributed/client.pyR   U  s    s)   Waiting on futures to clear before gatherR}  R   R   R  t   skips   Bad value, `errors=%s`c         ` s/   i  |  ]% } |   j  k r   j  | |  q S(    (   t   data(   R(  R^   (   t   local_worker(    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>  s   	 R[   s(   Couldn't gather %s keys, rescheduling %sRg   s
   report-keyRf   Ri   R  (   R   R   (-   R%   RZ   RG   Ri   R   R\   R   R@   RK  Rj   R   R   R   R   R   Rn  RE   R   RB   Ro   R   R[   t   addR   R   R   Rc   R   R   R   R   RV  R  R   R   t   _gather_remoteR{  R*  Rr   R   R  RX   R&   R   R   (   Ru   Ro   R  t   directR  t   unpackedt
   future_setR   Rg   t   bad_dataR  R)  R   Ri   t   failedt
   exceptionst   bad_keysRf  R   R   R^   t   responset   logR   R   (    (   R  R  Ru   s1   lib/python2.7/site-packages/distributed/client.pyR   C  s    "	
	.		%	1(		!(c         c` s3  |  j  j   Vt |  j  } d |  _ d |  _ z | s> | r |  j j d |  V} t | d |  j	 d t
 V\ } } } i d d 6| d 6} | rg  | D] }	 |	 | k r |	 ^ q }
 |  j j d |
  V} | d d k r | d j |  q qn |  j j d |  V} Wd |  j  j   Xt j |   d S(   s    Perform gather with workers or scheduler

        This method exists to limit and batch many concurrent gathers into a
        few.  In controls access using a Tornado semaphore, and picks up keys
        from other requests made recently.
        Rg   R0   Rt  t   OKR[   R  N(   R   t   acquireRX   R   R\   R   R   t   who_hasR(   R0   Rj   t   gatherR  R   R   R   (   Ru   R  R  Rg   R  t   data2t   missing_keyst   missing_workersR  Ri   t   keys2(    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s$    		"%c         K` s   x t  r | j   g } x< | j   rV y | j | j    Wq t k
 rR Pq Xq W|  j | |  } x | D] } | j |  qp Wq Wd S(   s'    Internal function for gathering Queue N(   RZ   R   t   emptyRH  t
   get_nowaitR*   R  R  (   Ru   t   qint   qoutR   R]   t   resultst   item(    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _threaded_gather  s    		i    c   	      ` s   t  |  rm t d |  } t j d  j d d d | | f d i  d 6  d 6 } t | _ | j   | St | t	  r     f d	   | D St
 t d
  r t j d } n d }  j  j | d  d   d | d | Sd S(   sP   Gather futures from distributed memory

        Accepts a future, nested container of futures, iterator, or queue.
        The return type will match the input type.

        Parameters
        ----------
        futures: Collection of futures
            This can be a possibly nested collection of Future objects.
            Collections can be lists, sets, iterators, queues or dictionaries
        errors: string
            Either 'raise' or 'skip' if we should raise if a future has erred
            or skip its inclusion in the output collection
        direct: boolean
            Whether or not to connect directly to the workers, or to ask
            the scheduler to serve as intermediary.  This can also be set when
            creating the Client.
        maxsize: int
            If the input is a queue then this produces an output queue with a
            maximum size.

        Returns
        -------
        results: a collection of the same type as the input, but now with
        gathered results rather than futures

        Examples
        --------
        >>> from operator import add  # doctest: +SKIP
        >>> c = Client('127.0.0.1:8787')  # doctest: +SKIP
        >>> x = c.submit(add, 1, 2)  # doctest: +SKIP
        >>> c.gather(x)  # doctest: +SKIP
        3
        >>> c.gather([x, [x], x])  # support lists and dicts # doctest: +SKIP
        [3, [3], 3]

        >>> seq = c.gather(iter([x, x]))  # support iterators # doctest: +SKIP
        >>> next(seq)  # doctest: +SKIP
        3

        See Also
        --------
        Client.scatter: Send data out to cluster
        R  R  R  s   Threaded gather()R%  R   R  R  c         3` s*   |  ]  }  j  | d   d   Vq d S(   R  R  N(   R  (   R(  R   (   R  R  Ru   (    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>  s    t   execution_stateR   R  R   N(   R+   R  R   R  R  RZ   R  R  R  R.   R  RM   R  R\   RC   R   (	   Ru   Ro   R  R  R  R   R  R  R  (    (   R  R  Ru   s1   lib/python2.7/site-packages/distributed/client.pyR    s,    /			
c         #` s  | t  k r  j } n  t | t j t f  r= | g } n  t | t  r t d   | D  r  j t	 t
 |  | |  V  t j   f d   | D   n  t | t t d    r t |  } n  t |  } t }	 t }
 t | t  rt |  } n  t | t t f  r(t |  } n  t | t t t t t f  sXt }
 | g } n  t | t t f  r| rg  | D]# } t |  j d t |  ^ qz}	 n3 g  | D]& } t |  j d t j   j ^ q}	 t t |	 |   } n  t | t  st  t t |  } | d  k r- j } n  | d  k ry t    } Wn t! k
 r_t } qX| j" j#  j" j# k rt } qn   r j$ d | d t   j" j$ d  f d   | D d	 t t% |  d
  j&  Vnt t' |  } | rd  } t(   } xb | sg| d  k	 r)t j) d  Vn  t(   | | k rNt j* d   n   j" j+ d |  V} qW| s}t, d   n  t- | | d t d  j. V\ } } }  j" j$ d | d	 | d
  j&  Vn/  j" j/ d | d | d
  j& d | d |  V f d   | D  x1 | j0   D]# \ } }  j1 | j2 d |  qW| r| r| t k rbd  n | }  j3 t  j4    d | d | Vn  t5 | t t t t f  r|  f d   |	 D   n  |
 rt6   d k st  t  j4    d  n  t j    d  S(   Nc         s` s$   |  ] } t  | t t f  Vq d  S(   N(   R  t   bytesR   (   R(  R^   (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>1  s    c         ` s#   i  |  ] }   t  |  |  q S(    (   RG   (   R(  R^   (   t   d(    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>4  s   	 i    R   R  t   reportR  c         ` s   i  |  ] }   j  g |  q S(    (   R   (   R(  Ri   (   R  (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>\  s   	 t   nbytesRh   g?s   No valid workers foundR&  s   No valid workersR0   t	   broadcastR   c         ` s(   i  |  ] } t  |   d  t |  q S(   Rv   (   Re   Rj   (   R(  R^   (   Ru   (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>  s   	 R   t   nc         3` s   |  ] }   | Vq d  S(   N(    (   R(  R^   (   t   out(    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>  s    i   (7   RN   R   R  R   R  R   R   R  t   _scatterR   RG   R   R   R   RR  RX   Rj   R.   R   t	   frozensetRw  RZ   R   R   R   R  t   hexR  R  R   R\   R   R@   RK  R   R   t   update_dataR<   Rs   R6   R4   RQ  R   R'  RV  R'   R0   t   scatterR  Ro   R   t
   _replicateR,  t
   issubclassR*  (   Ru   R  R&  R  R  R  R   t   hasht
   input_typet   namest   unpackt   xt   typesR)  R  R'  R  R   R  R  Ri   R   R  (    (   R  R  R  Ru   s1   lib/python2.7/site-packages/distributed/client.pyR  !  s    "33
		%	)c         K` s   x t  r t |  rf | j   g } xv | j   sb y | j | j    Wq' t k
 r^ Pq' Xq' Wn7 y t |  g } Wn! t k
 r } | j	 |  Pn X|  j
 | |  } x | D] } | j	 |  q Wq Wd S(   s6    Internal function for scattering Iterable/Queue data N(   RZ   R+   R   R  RH  R  R*   R  R  R  R  (   Ru   t   q_or_iR  R   R]   Ra  Ro   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _threaded_scatter  s     	c	         C` s   | t  k r |  j } n  t |  s3 t | t  r t j d  t d |  }	 t j	 d |  j
 d d d | |	 f d i | d 6| d	 6 }
 t |
 _ |
 j   t |  r |	 St |	  Snb t t d
  r t j d } n d } |  j |  j | d | d	 | d | d | d | d | d | Sd S(   s   Scatter data into distributed memory

        This moves data from the local client process into the workers of the
        distributed scheduler.  Note that it is often better to submit jobs to
        your workers to have them load the data rather than loading data
        locally and then scattering it out to them.

        Parameters
        ----------
        data: list, iterator, dict, Queue, or object
            Data to scatter out to workers.  Output type matches input type.
        workers: list of tuples (optional)
            Optionally constrain locations of data.
            Specify workers as hostname/port pairs, e.g. ``('127.0.0.1', 8787)``.
        broadcast: bool (defaults to False)
            Whether to send each data element to all workers.
            By default we round-robin based on number of cores.
        direct: bool (defaults to automatically check)
            Whether or not to connect directly to the workers, or to ask
            the scheduler to serve as intermediary.  This can also be set when
            creating the Client.
        maxsize: int (optional)
            Maximum size of queue if using queues, 0 implies infinite
        hash: bool (optional)
            Whether or not to hash data to determine key.
            If False then this uses a random key

        Returns
        -------
        List, dict, iterator, or queue of futures matching the type of input.

        Examples
        --------
        >>> c = Client('127.0.0.1:8787')  # doctest: +SKIP
        >>> c.scatter(1) # doctest: +SKIP
        <Future: status: finished, key: c0a8a20f903a4915b94db8de3ea63195>

        >>> c.scatter([1, 2, 3])  # doctest: +SKIP
        [<Future: status: finished, key: c0a8a20f903a4915b94db8de3ea63195>,
         <Future: status: finished, key: 58e78e1b34eb49a68c65b54815d1b158>,
         <Future: status: finished, key: d3395e15f605bc35ab1bac6341a285e2>]

        >>> c.scatter({'x': 1, 'y': 2, 'z': 3})  # doctest: +SKIP
        {'x': <Future: status: finished, key: x>,
         'y': <Future: status: finished, key: y>,
         'z': <Future: status: finished, key: z>}

        Constrain location of data to subset of workers

        >>> c.scatter([1, 2, 3], workers=[('hostname', 8788)])   # doctest: +SKIP

        Handle streaming sequences of data with iterators or queues

        >>> seq = c.scatter(iter([1, 2, 3]))  # doctest: +SKIP
        >>> next(seq)  # doctest: +SKIP
        <Future: status: finished, key: c0a8a20f903a4915b94db8de3ea63195>,

        Broadcast data to all workers

        >>> [future] = c.scatter([element], broadcast=True)  # doctest: +SKIP

        Send scattered data to parallelized function using client futures
        interface

        >>> data = c.scatter(data, broadcast=True)  # doctest: +SKIP
        >>> res = [c.submit(func, data, i) for i in range(100)]

        See Also
        --------
        Client.gather: Gather data back to local process
        s"   Starting thread for streaming dataR  R  R  s   Threaded scatter()R%  R   R&  R  R  R   R  R  R   R   R  N(   RN   R   R+   R  R.   R   Rn  R  R   R  R  RZ   R  R  RF   R  RM   R  R\   RC   R  (   Ru   R  R&  R  R  R  R  R   R   R  R  R  (    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s8    R			
c         c` s   t  d   t |  D  } |  j j d | d |  j d |  Vx< | D]4 } |  j j | d   } | d  k	 rF | j   qF qF Wd  S(   Nc         S` s   h  |  ] } t  | j   q S(    (   RG   Ri   (   R(  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <setcomp>  s   	 Rg   Rh   t   force(   RX   t
   futures_ofR   R   Rs   Ro   R!  R\   (   Ru   Ro   R  Rg   R^   Rf  (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _cancel  s    #c         C` s   |  j  |  j | d | d | S(   s  
        Cancel running futures

        This stops future tasks from being scheduled if they have not yet run
        and deletes them if they have already run.  After calling, this result
        and all dependent results will no longer be accessible

        Parameters
        ----------
        futures: list of Futures
        force: boolean (False)
            Cancel this future even if other clients desire it
        R   R  (   RC   R  (   Ru   Ro   R   R  (    (    s1   lib/python2.7/site-packages/distributed/client.pyR   #  s    c         c` sg   t  d   t |  D  } |  j j d | d |  j  V} x% | D] } |  j | } | j   qB Wd  S(   Nc         S` s   h  |  ] } t  | j   q S(    (   RG   Ri   (   R(  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <setcomp>5  s   	 Rg   Rh   (   RX   R  R   R   Rs   Ro   (   Ru   Ro   Rg   R  Ri   Rf  (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _retry3  s
    c         C` s   |  j  |  j | d | S(   sn   
        Retry failed futures

        Parameters
        ----------
        futures: list of Futures
        R   (   RC   R  (   Ru   Ro   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR   ;  s    c         /` s   t     g       f d   } | j d d   } | r t |  d k r[ t d   n t |  d k rz | d } n  | | |  n  x' | j   D] \ } } | | |  q W  VWd  QXd  S(   Nc      
   ` sc   g  t  |  D] } t | j  ^ q }   j  j j d | d |  d t |  d  j   d  S(   NRg   R  R  Rh   (   R  RG   Ri   RH  R   t   publish_putR6   Rs   (   R  R  R   Rg   (   R   Ru   (    s1   lib/python2.7/site-packages/distributed/client.pyt   add_coroJ  s    (R  i    sQ   If name is provided, expecting call signature like publish_dataset(df, name='ds')i   (   RH   R!  R\   R*  RV  R  (   Ru   R%  R   R  R  R  (    (   R   Ru   s1   lib/python2.7/site-packages/distributed/client.pyt   _publish_datasetE  s    
c         O` s   |  j  |  j | |  S(   s  
        Publish named datasets to scheduler

        This stores a named reference to a dask collection or list of futures
        on the scheduler.  These references are available to other Clients
        which can download the collection or futures with ``get_dataset``.

        Datasets are not immediately computed.  You may wish to call
        ``Client.persist`` prior to publishing a dataset.

        Parameters
        ----------
        args : list of objects to publish as name
        name : optional name of the dataset to publish
        kwargs: dict
            named collections to publish on the scheduler

        Examples
        --------
        Publishing client:

        >>> df = dd.read_csv('s3://...')  # doctest: +SKIP
        >>> df = c.persist(df) # doctest: +SKIP
        >>> c.publish_dataset(my_dataset=df)  # doctest: +SKIP

        Alternative invocation
        >>> c.publish_dataset(df, name='my_dataset')

        Receiving client:

        >>> c.list_datasets()  # doctest: +SKIP
        ['my_dataset']
        >>> df2 = c.get_dataset('my_dataset')  # doctest: +SKIP

        Returns
        -------
        None

        See Also
        --------
        Client.list_datasets
        Client.get_dataset
        Client.unpublish_dataset
        Client.persist
        (   RC   R  (   Ru   R%  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   publish_datasetc  s    .c         K` s   |  j  |  j j d | | S(   s^  
        Remove named datasets from scheduler

        Examples
        --------
        >>> c.list_datasets()  # doctest: +SKIP
        ['my_dataset']
        >>> c.unpublish_datasets('my_dataset')  # doctest: +SKIP
        >>> c.list_datasets()  # doctest: +SKIP
        []

        See Also
        --------
        Client.publish_dataset
        R  (   RC   R   t   publish_delete(   Ru   R  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   unpublish_dataset  s    c         K` s   |  j  |  j j |  S(   s   
        List named datasets available on the scheduler

        See Also
        --------
        Client.publish_dataset
        Client.get_dataset
        (   RC   R   t   publish_list(   Ru   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   list_datasets  s    	c         c` sn   |  j  j d | d |  j  V} | d  k r> t d |   n  t |    | d } Wd  QXt j |   d  S(   NR  Rh   s   Dataset '%s' not foundR  (   R   t   publish_getRs   R\   Rc   t   temp_default_clientR   R   (   Ru   R  R  R  (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _get_dataset  s    c         K` s   |  j  |  j | |  S(   s   
        Get named dataset from the scheduler

        See Also
        --------
        Client.publish_dataset
        Client.list_datasets
        (   RC   R  (   Ru   R  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   get_dataset  s    	c      	   o` s   | j  d t  } |  j j d t |  d t |  d t |  d |  V} | d d k rr t j t |     n t j	 | d   d  S(   NR   t   functionR%  R   R[   R   R   (
   R!  RZ   R   t   run_functionR7   R   R   R1   R   R   (   Ru   R  R%  R   R   R  (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _run_on_scheduler  s    .c         O` s   |  j  |  j | | |  S(   s   Run a function on the scheduler process

        This is typically used for live debugging.  The function should take a
        keyword argument ``dask_scheduler=``, which will be given the scheduler
        object itself.

        Examples
        --------

        >>> def get_number_of_tasks(dask_scheduler=None):
        ...     return len(dask_scheduler.tasks)

        >>> client.run_on_scheduler(get_number_of_tasks)  # doctest: +SKIP
        100

        Run asynchronous functions in the background:

        >>> async def print_state(dask_scheduler):  # doctest: +SKIP
        ...    while True:
        ...        print(dask_scheduler.status)
        ...        await gen.sleep(1)

        >>> c.run(print_state, wait=False)  # doctest: +SKIP

        See Also
        --------
        Client.run: Run a function on all workers
        Client.start_ipython_scheduler: Start an IPython session on scheduler
        (   RC   R  (   Ru   R  R%  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   run_on_scheduler  s    c         o` s  | j  d t  } | j  d d   } | j  d t  } |  j j d t d d d t |  d t |  d | d	 t |   d | d |  V} i  } xa | j   D]S \ }	 }
 |
 d
 d k r |
 d | |	 <q |
 d
 d k r t	 j
 t |
     q q W| rt j |   n  d  S(   Nt   nannyR&  R   RI  Rf   t   runR  R%  R   R[   R  R   R   (   R!  Rj   R\   RZ   R   R  R   R7   R  R   R   R1   R   R   (   Ru   R  R%  R   R  R&  R   t	   responsesR  Ri   t   resp(    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _run  s(    
c         O` s   |  j  |  j | | |  S(   s  
        Run a function on all workers outside of task scheduling system

        This calls a function on all currently known workers immediately,
        blocks until those results come back, and returns the results
        asynchronously as a dictionary keyed by worker address.  This method
        if generally used for side effects, such and collecting diagnostic
        information or installing libraries.

        If your function takes an input argument named ``dask_worker`` then
        that variable will be populated with the worker itself.

        Parameters
        ----------
        function: callable
        *args: arguments for remote function
        **kwargs: keyword arguments for remote function
        workers: list
            Workers on which to run the function. Defaults to all known workers.
        wait: boolean (optional)
            If the function is asynchronous whether or not to wait until that
            function finishes.

        Examples
        --------
        >>> c.run(os.getpid)  # doctest: +SKIP
        {'192.168.0.100:9000': 1234,
         '192.168.0.101:9000': 4321,
         '192.168.0.102:9000': 5555}

        Restrict computation to particular workers with the ``workers=``
        keyword argument.

        >>> c.run(os.getpid, workers=['192.168.0.100:9000',
        ...                           '192.168.0.101:9000'])  # doctest: +SKIP
        {'192.168.0.100:9000': 1234,
         '192.168.0.101:9000': 4321}

        >>> def get_status(dask_worker):
        ...     return dask_worker.status

        >>> c.run(get_hostname)  # doctest: +SKIP
        {'192.168.0.100:9000': 'running',
         '192.168.0.101:9000': 'running}

        Run asynchronous functions in the background:

        >>> async def print_state(dask_worker):  # doctest: +SKIP
        ...    while True:
        ...        print(dask_worker.status)
        ...        await gen.sleep(1)

        >>> c.run(print_state, wait=False)  # doctest: +SKIP
        (   RC   R  (   Ru   R  R%  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR  		  s    7c         O` s&   t  j d d d |  j | | |  S(   s  
        Spawn a coroutine on all workers.

        This spaws a coroutine on all currently known workers and then waits
        for the coroutine on each worker.  The coroutines' results are returned
        as a dictionary keyed by worker address.

        Parameters
        ----------
        function: a coroutine function
            (typically a function wrapped in gen.coroutine or
             a Python 3.5+ async function)
        *args: arguments for remote function
        **kwargs: keyword arguments for remote function
        wait: boolean (default True)
            Whether to wait for coroutines to end.
        workers: list
            Workers on which to run the function. Defaults to all known workers.

        sc   This method has been deprecated. Instead use Client.run which detects async functions automaticallyt
   stackleveli   (   R  R  R  (   Ru   R  R%  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   run_coroutineB	  s    c      
   ` s   j  | r4  j | d t j   |  } n   r^  j  d t j   |   n  |
 d  k	 r |
 t k	 r |
 t k	 r t  j	 |
   }
 n  t
 |   t t t |   }  f d    D }  f d     j   D } | rt j j   d |   n  d     j   D } | rVt
 j g  | j   D] } | d ^ q=  n t
   } d   | D } t d   | j   D |  } d	   | j   D } x2 | D]* } | j  k	 rd
 } t |   qqW| r t t |  } t t |  } n  | d  k	 r$t t t |   } n  d   | j   D } xC | j   D]5 } x, | D]$ } |  j k rTt |   qTqTWqGW  f d     D } | d  k rt j j   d | } t t |  } n  d   | j   D } xI | j   D]; \ } } | rt t
 | j | d   | B | | <qqWt  t  rb d k rb f d   | D  n   j i d d 6t t |  d 6| d 6t |  d 6| pi  d 6| d 6| d 6| d 6| d 6t  t! d d   d 6 d 6|	 d 6|
 d 6 | SWd  QXd  S(   Nt   all_keysc         ` s(   i  |  ] } t  |   d  t |  q S(   Rv   (   Re   Rj   (   R(  Ri   (   Ru   (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>|	  s   	 c         ` s7   h  |  ]- \ } } t  | t  r |   k r |  q S(    (   R  Re   (   R(  R^   R  (   t   keyset(    s1   lib/python2.7/site-packages/distributed/client.pys	   <setcomp>	  s   	 Rg   c         S` s+   i  |  ]! \ } } t  | d  t |  q S(   R  (   R%   RZ   (   R(  R^   R  (    (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>	  s   	 i   c         S` s   h  |  ] } t  | j   q S(    (   RG   Ri   (   R(  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <setcomp>	  s   	 c         S` s#   i  |  ] \ } } | d  |  q S(   i    (    (   R(  R^   R  (    (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>	  s   	 c         S` s+   i  |  ]! \ } } | | k	 r | |  q S(    (    (   R(  R^   R  (    (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>	  s   	 s;   Inputs contain futures that were created by another client.c         S` s3   i  |  ]) \ } } d    | d D t  |   q S(   c         S` s   h  |  ] } t  | j   q S(    (   RG   Ri   (   R(  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <setcomp>	  s   	 i   (   RG   (   R(  R^   R  (    (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>	  s   	 c         ` s"   i  |  ] } t    |  |  q S(    (   R   (   R(  R^   (   R  (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>	  s   	 t   dependenciesc         S` s>   i  |  ]4 \ } } g  | D] } t  |  ^ q t  |   q S(    (   RG   (   R(  R^   t   depst   dep(    (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>	  s   	i    c         ` s   i  |  ] }   |  q S(    (    (   R(  R^   (   R  (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>	  s   	 s   update-graphRf   R   R  R  R  R  R  Ri   t   submitting_taskR  R  R  (    ("   R   t   _expand_resourcest	   itertoolst   chaint   _expand_retriesR\   RZ   Rj   RX   t   _expand_keyR   R  RG   R  R   t   optimizationt   inlinet   unionR,  RI   Rh   RV  R   R   Ro   R   t   orderR   R  R   Rr   R>   R"  RM   (   Ru   R  Rg   R  R  R  R  R  R  R  R  t   flatkeysRo   R,  R  R  t   extra_futurest
   extra_keyst   dsk2t   dsk3R   RI  t   future_dependenciesR   R  R^   R  (    (   R  R  R  Ru   s1   lib/python2.7/site-packages/distributed/client.pyR  _	  sz    
$;-t   60sc         K` s  |  j  | d t t | g   d | d | d | d | d |	 d |
 d | } t | |  } | rt t d	 t  r y t   t } Wq t	 k
 r t } q Xn  z |  j
 | d
 | d | } Wd x | j   D] } | j   q Wt t d	 t  r| rt   n  X| S| S(   s   Compute dask graph

        Parameters
        ----------
        dsk: dict
        keys: object, or nested lists of objects
        restrictions: dict (optional)
            A mapping of {key: {set of worker hostnames}} that restricts where
            jobs can take place
        retries: int (default to 0)
            Number of allowed automatic retries if computing a result fails
        priority: Number
            Optional prioritization of task.  Zero is default.
            Higher priorities take precedence
        sync: bool (optional)
            Returns Futures if False or concrete values if True (default).
        direct: bool
            Whether or not to connect directly to the workers, or to ask
            the scheduler to serve as intermediary.  This can also be set when
            creating the Client.

        Examples
        --------
        >>> from operator import add  # doctest: +SKIP
        >>> c = Client('127.0.0.1:8787')  # doctest: +SKIP
        >>> c.get({'x': (add, 1, 2)}, 'x')  # doctest: +SKIP
        3

        See Also
        --------
        Client.compute: Compute asynchronous collections
        Rg   R  R  R  R  R  R  R  Ri   R   R  N(   R  R   R   R&   R"  RM   Rj   RA   RZ   RK  R  R,  R   R=   (   Ru   R  Rg   R  R  R  RC   R   R  R  R  R  R  R   Ro   t   packedt   should_rejoinR  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR   	  s4    0	
c      
   C` s   |  j  n t } x` t |  D]R } t |  |  j k r | sS t } t |  } n  t | |  d t | | <q q WWd QX| r t j	 j
 | |  \ } } n  | S(   sx   Replace known keys in dask graph with Futures

        When given a Dask graph that might have overlapping keys with our known
        results we replace the values of that graph with futures.  This can be
        used as an optimization to avoid recomputation.

        This returns the same graph if unchanged but a new graph if any changes
        were necessary.
        Rv   N(   R   Rj   RX   RG   Ro   RZ   R   Re   R   R  t   cull(   Ru   R  Rg   t   changedRi   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _optimize_insert_futures
  s    

&c         C` sE   | j    } |  j | | j    } | | k r4 | St | |  Sd S(   sA  
        Replace collection's tasks by already existing futures if they exist

        This normalizes the tasks within a collections task graph against the
        known futures within the scheduler.  It returns a copy of the
        collection with a task graph that includes the overlapping futures.

        Examples
        --------
        >>> len(x.__dask_graph__())  # x is a dask collection with 100 tasks  # doctest: +SKIP
        100
        >>> set(client.futures).intersection(x.__dask_graph__())  # some overlap exists  # doctest: +SKIP
        10

        >>> x = client.normalize_collection(x)  # doctest: +SKIP
        >>> len(x.__dask_graph__())  # smaller computational graph  # doctest: +SKIP
        20

        See Also
        --------
        Client.persist: trigger computation of collection's tasks
        N(   t   __dask_graph__R  t   __dask_keys__t   redict_collection(   Ru   t
   collectiont   dsk_origR  (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   normalize_collection)
  s
    c         ` sw  t  | t t t t f  r$ t } n | g } t } | j d t  } | rd t d   | D  } n  g  | D] } t j	 |  rk | ^ qk }   j
 | | |  } g  | D] } d t |  ^ q } i  } x t t | |   D]z \ } \ } } | j   \ } } | j   } | t k rFt |  d k rF| rF| d | | <q | | f | | | <q W  j | | |  \ } } t  | t  s  f d   | j   D } n    j t | |  | | | d | d | d	 | d
 |	 d |
 } d } g  } xL | D]D } t j	 |  r0| j | | |  | d 7} q| j |  qW| rY  j |  } n | } | rot |  S| Sd S(   s   Compute dask collections on cluster

        Parameters
        ----------
        collections: iterable of dask objects or single dask object
            Collections like dask.array or dataframe or dask.value objects
        sync: bool (optional)
            Returns Futures if False (default) or concrete values if True
        optimize_graph: bool
            Whether or not to optimize the underlying graphs
        workers: str, list, dict
            Which workers can run which parts of the computation
            If a string a list then the output collections will run on the listed
            workers, but other sub-computations can run anywhere
            If a dict then keys should be (tuples of) collections and values
            should be addresses or lists.
        allow_other_workers: bool, list
            If True then all restrictions in workers= are considered loose
            If a list then only the keys for the listed collections are loose
        retries: int (default to 0)
            Number of allowed automatic retries if computing a result fails
        priority: Number
            Optional prioritization of task.  Zero is default.
            Higher priorities take precedence
        fifo_timeout: timedelta str (defaults to '60s')
            Allowed amount of time between calls to consider the same priority
        **kwargs:
            Options to pass to the graph optimize calls

        Returns
        -------
        List of Futures if input is a sequence, or a single future otherwise

        Examples
        --------
        >>> from dask import delayed
        >>> from operator import add
        >>> x = delayed(add)(1, 2)
        >>> y = delayed(add)(x, x)
        >>> xx, yy = client.compute([x, y])  # doctest: +SKIP
        >>> xx  # doctest: +SKIP
        <Future: status: finished, key: add-8f6e709446674bad78ea8aeecfee188e>
        >>> xx.result()  # doctest: +SKIP
        3
        >>> yy.result()  # doctest: +SKIP
        6

        Also support single arguments

        >>> xx = client.compute(x)  # doctest: +SKIP

        See Also
        --------
        Client.get: Normal synchronous dask.get function
        t   traversec         s` sB   |  ]8 } t  | t t t t t f  r6 t j |  n | Vq d  S(   N(   R  RX   R   Rw  R   R.   R   R  (   R(  t   a(    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>
  s   s   finalize-%si   i    c         ` s5   i  |  ]+ \ } }   j  |  D] } | |  q q S(    (   R  (   R(  R_   t   pR^   (   Ru   (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>
  s   	 R  R  R  R  R  N(   R  RX   Rw  R   R  Rj   RZ   R!  R   t   is_dask_collectionR   R   t	   enumerateR  t   __dask_postcompute__R!  R   R*  t   get_restrictionsR   R  R  R   RH  R  R   (   Ru   t   collectionsRC   t   optimize_graphR&  R  R  R  R  R  R  R   t	   singletonR&  R'  t	   variablesR  R  R  R  R_  R  R$  t
   extra_argsRg   R  R  t   futures_dictRo   t   argR   (    (   Ru   s1   lib/python2.7/site-packages/distributed/client.pyt   computeH
  s\    E		(#(%	
c
         ` s  t  | t t t t f  r$ t } n t } | g } t t t	 j
 |   sQ t   j | | |
  } d   | D }  j | | |  \ } } t  | t  s  f d   | j   D } n   j | | | | d | d | d | d | d |	   g  | D] } | j   ^ q } g  t | |  D]= \ \ } } } |   f d   t | j    D |  ^ q$} | rwt |  S| Sd	 S(
   sG   Persist dask collections on cluster

        Starts computation of the collection on the cluster in the background.
        Provides a new dask collection that is semantically identical to the
        previous one, but now based off of futures currently in execution.

        Parameters
        ----------
        collections: sequence or single dask object
            Collections like dask.array or dataframe or dask.value objects
        optimize_graph: bool
            Whether or not to optimize the underlying graphs
        workers: str, list, dict
            Which workers can run which parts of the computation
            If a string a list then the output collections will run on the listed
            workers, but other sub-computations can run anywhere
            If a dict then keys should be (tuples of) collections and values
            should be addresses or lists.
        allow_other_workers: bool, list
            If True then all restrictions in workers= are considered loose
            If a list then only the keys for the listed collections are loose
        retries: int (default to 0)
            Number of allowed automatic retries if computing a result fails
        priority: Number
            Optional prioritization of task.  Zero is default.
            Higher priorities take precedence
        fifo_timeout: timedelta str (defaults to '60s')
            Allowed amount of time between calls to consider the same priority
        kwargs:
            Options to pass to the graph optimize calls

        Returns
        -------
        List of collections, or single collection, depending on type of input.

        Examples
        --------
        >>> xx = client.persist(x)  # doctest: +SKIP
        >>> xx, yy = client.persist([x, y])  # doctest: +SKIP

        See Also
        --------
        Client.compute
        c         S` s/   h  |  ]% } t  | j    D] } |  q q S(    (   R   R!  (   R(  R_   R^   (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <setcomp>  s   	 c         ` s5   i  |  ]+ \ } }   j  |  D] } | |  q q S(    (   R  (   R(  R_   R(  R^   (   Ru   (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>  s   	 R  R  R  R  R  c         ` s   i  |  ] }   | |  q S(    (    (   R(  R^   (   Ro   (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>)  s   	 N(   R  Rw  RX   R   R  Rj   RZ   R  R  R   R)  R  R   R,  R   R  R  t   __dask_postpersist__R  R   R!  R   (   Ru   R-  R.  R&  R  R  R  R  R  R  R   R/  R  R  R  R  R_   t   postpersistsR$  R%  R   (    (   Ro   Ru   s1   lib/python2.7/site-packages/distributed/client.pyt   persist
  s6    9			P
c         #` sd   t  j j |  d   |  j |    Vd    f d  } |  j | d t Vt j   d    d  S(   Ni   c   
      ` s;  d d l  m } d d  l } d d  l } |   t j j |  j    } t j j |  j    } t j j	 |  } | j
 | |  | j |   } | j d |  Wd  QXxS t t j j |   d  d d   D], } t j |  }	 t j | |	 j d B q Wt j j t j j |   d    s-t  | SWd  QXd  S(   Ni    (   RH   RO  it   bint   *i@   (   t   distributed.utilsRH   t   zipfilet   shutilR   RO  t   joint
   worker_dirt	   local_dirt   dirnamet   movet   ZipFilet
   extractallR
   t   statt   chmodt   st_modeRP  R  (
   t   dask_workerRH   R;  R<  R'  t   bR_   R   R   Rf  (   R  (    s1   lib/python2.7/site-packages/distributed/client.pyt   unzip7  s    
,+R  i(	   R   RO  R:  t   _upload_large_fileR\   R  RZ   R   R   (   Ru   R;  RI  (    (   R  s1   lib/python2.7/site-packages/distributed/client.pyt   _upload_environment2  s
    c         C` s   |  j  |  j | |  S(   N(   RC   RK  (   Ru   R  R;  (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   upload_environmentO  s    c         c` s   | t  k r |  j d } n  |  j i d d 6| d 6 t   |  _ y" |  j j |  j j   |  VWn$ t j	 k
 r t
 j d |  n X|  j d 7_ |  j  |  j j   Wd  QXt j |    d  S(   Ni   R   Rf   R   s"   Restart timed out after %f secondsi   (   RN   R   Rr   R   Rz  R   R   R4   R   R   R   R   Rm   R   R   R   R   (   Ru   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _restartR  s    "
c         K` s   |  j  |  j |  S(   s    Restart the distributed network

        This kills all active work, deletes all data on the network, and
        restarts the worker processes.
        (   RC   RM  (   Ru   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR   c  s    c   	      #` s  t  | d   } | j     Wd  QXt j j |  \ } } |  j j d i d d 6| d 6t    d 6 V} t d   | j	   D  r g  | j	   D]  } | d d	 k r | d
 ^ q } | r | d  q t
 j | d   n  t   f d   | j	   D  st  d  S(   Nt   rbRI  t   upload_fileRf   t   filenameR  c         s` s   |  ] } | d  d k Vq d S(   R[   R   N(    (   R(  R  (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>t  s    R[   R   R   i    c         3` s%   |  ] } t     | d  k Vq d S(   R  N(   R*  (   R(  R  (   R  (    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>{  s    (   RS  Rm  R   RO  R:  R   R  R6   t   anyR,  R   R   R  R  (	   Ru   RP  t   raise_on_errorR   R   R   R  R  R  (    (   R  s1   lib/python2.7/site-packages/distributed/client.pyt   _upload_filek  s    %3c         #` s    d  k r% t j j |  d  n  t | d   } | j     Wd  QX|  j   g  V\ } | j  |  j |  Vd    f d  } |  j	 |  V} t
   f d   | j   D  s t  d  S(   Ni   RN  c         ` sp   t  j j   s- t  j j |  j   } n  } t | d   } | j |  j    Wd  QXt |  j    S(   Nt   wb(	   R   RO  t   isabsR=  R?  RS  Rl  R  R*  (   RG  R   R   (   Ri   t   remote_filename(    s1   lib/python2.7/site-packages/distributed/client.pyt   dump_to_file  s    c         3` s!   |  ] } t     | k Vq d  S(   N(   R*  (   R(  R  (   R  (    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>  s    (   R\   R   RO  R:  RS  Rm  R  Ri   R  R  R  R,  R  (   Ru   t   local_filenameRV  R   R   RW  R  (    (   R  Ri   RV  s1   lib/python2.7/site-packages/distributed/client.pyRJ  }  s    	
c         K` sA   |  j  |  j | d |  j | } t | t  r9 |  n | Sd S(   sF   Upload local package to workers

        This sends a local file up to all worker nodes.  This file is placed
        into a temporary directory on Python's system path so any .py,  .egg
        or .zip  files will be importable.

        Parameters
        ----------
        filename: string
            Filename of .py, .egg or .zip file to send to workers

        Examples
        --------
        >>> client.upload_file('mylibrary.egg')  # doctest: +SKIP
        >>> from mylibrary import myfunc  # doctest: +SKIP
        >>> L = c.map(myfunc, seq)  # doctest: +SKIP
        RR  N(   RC   RS  R   R  RK  (   Ru   RP  R   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRO    s
    	c         c` s`   t  |  Vt d   |  j |  D  } |  j j d | d |  V} | d d k s\ t  d  S(   Nc         S` s   h  |  ] } t  | j   q S(    (   RG   Ri   (   R(  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <setcomp>  s   	 Rg   R&  R[   R  (   t   _waitRX   R  R   t	   rebalanceR  (   Ru   Ro   R&  Rg   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt
   _rebalance  s    c         K` s   |  j  |  j | | |  S(   s   Rebalance data within network

        Move data between workers to roughly balance memory burden.  This
        either affects a subset of the keys/workers or the entire network,
        depending on keyword arguments.

        This operation is generally not well tested against normal operation of
        the scheduler.  It it not recommended to use it while waiting on
        computations.

        Parameters
        ----------
        futures: list, optional
            A list of futures to balance, defaults all data
        workers: list, optional
            A list of workers on which to balance, defaults to all workers
        (   RC   R[  (   Ru   Ro   R&  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRZ    s    i   c      	   c` sZ   |  j  |  } t |  Vd   | D } |  j j d t |  d | d | d |  Vd  S(   Nc         S` s   h  |  ] } t  | j   q S(    (   RG   Ri   (   R(  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <setcomp>  s   	 Rg   R  R&  t   branching_factor(   R  RY  R   t	   replicateRX   (   Ru   Ro   R  R&  R\  Rg   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s
    c      
   K` s(   |  j  |  j | d | d | d | | S(   s   Set replication of futures within network

        Copy data onto many workers.  This helps to broadcast frequently
        accessed data and it helps to improve resilience.

        This performs a tree copy of the data throughout the network
        individually on each piece of data.  This operation blocks until
        complete.  It does not guarantee replication of data to future workers.

        Parameters
        ----------
        futures: list of futures
            Futures we wish to replicate
        n: int, optional
            Number of processes on the cluster on which to replicate the data.
            Defaults to all.
        workers: list of worker addresses
            Workers on which we want to restrict the replication.
            Defaults to all.
        branching_factor: int, optional
            The number of workers that can copy data in each generation

        Examples
        --------
        >>> x = c.submit(func, *args)  # doctest: +SKIP
        >>> c.replicate([x])  # send to all workers  # doctest: +SKIP
        >>> c.replicate([x], n=3)  # send to three workers  # doctest: +SKIP
        >>> c.replicate([x], workers=['alice', 'bob'])  # send to specific  # doctest: +SKIP
        >>> c.replicate([x], n=1, workers=['alice', 'bob'])  # send to one of specific workers  # doctest: +SKIP
        >>> c.replicate([x], n=1)  # reduce replications # doctest: +SKIP

        See also
        --------
        Client.rebalance
        R  R&  R\  (   RC   R  (   Ru   Ro   R  R&  R\  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR]    s    $c         K` s   t  | t  r4 t d   | D  r4 t |  } n  | d k	 re t  | t t t f  re | g } n  |  j |  j j d | | S(   s6   The number of threads/cores available on each worker node

        Parameters
        ----------
        workers: list (optional)
            A list of workers that we care about specifically.
            Leave empty to receive information about all workers.

        Examples
        --------
        >>> c.ncores()  # doctest: +SKIP
        {'192.168.1.141:46784': 8,
         '192.167.1.142:47548': 8,
         '192.167.1.143:47329': 8,
         '192.167.1.144:37297': 8}

        See Also
        --------
        Client.who_has
        Client.has_what
        c         s` s$   |  ] } t  | t t f  Vq d  S(   N(   R  R   Rw  (   R(  R_  (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>  s    R&  N(	   R  Rw  R  RX   R\   R   RC   R   R'  (   Ru   R&  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR'    s    %c         K` s_   | d k	 r= |  j |  } t t t d   | D   } n d } |  j |  j j d | | S(   sY   The workers storing each future's data

        Parameters
        ----------
        futures: list (optional)
            A list of futures, defaults to all data

        Examples
        --------
        >>> x, y, z = c.map(inc, [1, 2, 3])  # doctest: +SKIP
        >>> wait([x, y, z])  # doctest: +SKIP
        >>> c.who_has()  # doctest: +SKIP
        {'inc-1c8dd6be1c21646c71f76c16d09304ea': ['192.168.1.141:46784'],
         'inc-1e297fc27658d7b67b3a758f16bcf47a': ['192.168.1.141:46784'],
         'inc-fd65c238a7ea60f6a01bf4c8a5fcf44b': ['192.168.1.141:46784']}

        >>> c.who_has([x, y])  # doctest: +SKIP
        {'inc-1c8dd6be1c21646c71f76c16d09304ea': ['192.168.1.141:46784'],
         'inc-1e297fc27658d7b67b3a758f16bcf47a': ['192.168.1.141:46784']}

        See Also
        --------
        Client.has_what
        Client.ncores
        c         S` s   h  |  ] } | j   q S(    (   Ri   (   R(  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <setcomp><  s   	 Rg   N(   R\   R  RX   R  RG   RC   R   R  (   Ru   Ro   R   Rg   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR     s
    "c         K` s   t  | t  r4 t d   | D  r4 t |  } n  | d k	 re t  | t t t f  re | g } n  |  j |  j j d | | S(   s   Which keys are held by which workers

        This returns the keys of the data that are held in each worker's
        memory.

        Parameters
        ----------
        workers: list (optional)
            A list of worker addresses, defaults to all

        Examples
        --------
        >>> x, y, z = c.map(inc, [1, 2, 3])  # doctest: +SKIP
        >>> wait([x, y, z])  # doctest: +SKIP
        >>> c.has_what()  # doctest: +SKIP
        {'192.168.1.141:46784': ['inc-1c8dd6be1c21646c71f76c16d09304ea',
                                 'inc-fd65c238a7ea60f6a01bf4c8a5fcf44b',
                                 'inc-1e297fc27658d7b67b3a758f16bcf47a']}

        See Also
        --------
        Client.who_has
        Client.ncores
        Client.processing
        c         s` s$   |  ] } t  | t t f  Vq d  S(   N(   R  R   Rw  (   R(  R_  (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>\  s    R&  N(	   R  Rw  R  RX   R\   R   RC   R   t   has_what(   Ru   R&  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR^  A  s    %c         C` s~   t  | t  r4 t d   | D  r4 t |  } n  | d k	 re t  | t t t f  re | g } n  |  j |  j j d | S(   s   The tasks currently running on each worker

        Parameters
        ----------
        workers: list (optional)
            A list of worker addresses, defaults to all

        Examples
        --------
        >>> x, y, z = c.map(inc, [1, 2, 3])  # doctest: +SKIP
        >>> c.processing()  # doctest: +SKIP
        {'192.168.1.141:46784': ['inc-1c8dd6be1c21646c71f76c16d09304ea',
                                 'inc-fd65c238a7ea60f6a01bf4c8a5fcf44b',
                                 'inc-1e297fc27658d7b67b3a758f16bcf47a']}

        See Also
        --------
        Client.who_has
        Client.has_what
        Client.ncores
        c         s` s$   |  ] } t  | t t f  Vq d  S(   N(   R  R   Rw  (   R(  R_  (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>z  s    R&  N(	   R  Rw  R  RX   R\   R   RC   R   t
   processing(   Ru   R&  (    (    s1   lib/python2.7/site-packages/distributed/client.pyR_  c  s    %c         K` s"   |  j  |  j j d | d | | S(   s    The bytes taken up by each key on the cluster

        This is as measured by ``sys.getsizeof`` which may not accurately
        reflect the true cost.

        Parameters
        ----------
        keys: list (optional)
            A list of keys, defaults to all keys
        summary: boolean, (optional)
            Summarize keys into key types

        Examples
        --------
        >>> x, y, z = c.map(inc, [1, 2, 3])  # doctest: +SKIP
        >>> c.nbytes(summary=False)  # doctest: +SKIP
        {'inc-1c8dd6be1c21646c71f76c16d09304ea': 28,
         'inc-1e297fc27658d7b67b3a758f16bcf47a': 28,
         'inc-fd65c238a7ea60f6a01bf4c8a5fcf44b': 28}

        >>> c.nbytes(summary=True)  # doctest: +SKIP
        {'inc': 84}

        See Also
        --------
        Client.who_has
        Rg   t   summary(   RC   R   R  (   Ru   Rg   R`  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s    c         C` sl   | p	 g  } | d k	 rM |  j |  } | t t t d   | D   7} n  |  j |  j j d | ph d S(   s   The actively running call stack of all relevant keys

        You can specify data of interest either by providing futures or
        collections in the ``futures=`` keyword or a list of explicit keys in
        the ``keys=`` keyword.  If neither are provided then all call stacks
        will be returned.

        Parameters
        ----------
        futures: list (optional)
            List of futures, defaults to all data
        keys: list (optional)
            List of key names, defaults to all data

        Examples
        --------
        >>> df = dd.read_parquet(...).persist()  # doctest: +SKIP
        >>> client.call_stack(df)  # call on collections

        >>> client.call_stack()  # Or call with no arguments for all activity  # doctest: +SKIP
        c         S` s   h  |  ] } | j   q S(    (   Ri   (   R(  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <setcomp>  s   	 Rg   N(   R\   R  RX   R  RG   RC   R   t
   call_stack(   Ru   Ro   Rg   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRa    s
    &c         C` s_   t  | t j t f  r% | g } n  |  j |  j d | d | d | d | d | d | d | S(   s   Collect statistical profiling information about recent work

        Parameters
        ----------
        key: str
            Key prefix to select, this is typically a function name like 'inc'
            Leave as None to collect all data
        start: time
        stop: time
        workers: list
            List of workers to restrict profile information
        plot: boolean or string
            Whether or not to return a plot object
        filename: str
            Filename to save the plot

        Examples
        --------
        >>> client.profile()  # call on collections
        >>> client.profile(filename='dask-profile.html')  # save to html file
        Ri   R&  t   merge_workersR  R~  t   plotRP  (   R  R   R  R   RC   t   _profile(   Ru   Ri   R  R~  R&  Rb  Rc  RP  (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   profile  s    	c         c` s  t  | t j t f  r% | g } n  |  j j d | d | d | d | d |  V} | rb t } n  | r d d l m }	 |	 j |  }
 |	 j	 |
 d d	 \ } } | d
 k r | r d } n  d d l
 m } | | d d d | t j | | f   n t j |   d  S(   NRi   R&  Rb  R  R~  i   (   Re  t   sizing_modet   stretch_botht   saves   dask-profile.htmli    (   Rh  t   titles   Dask ProfileRP  (   R  R   R  R   R   Re  RZ   R   t	   plot_datat   plot_figuret   bokeh.plottingRh  R   R   (   Ru   Ri   R  R~  R&  Rb  Rc  RP  Rw   Re  R  t   figuret   sourceRh  (    (    s1   lib/python2.7/site-packages/distributed/client.pyRd    s(    
		c         K` s   |  j  |  j  |  j S(   s   Basic information about the workers in the cluster

        Examples
        --------
        >>> c.scheduler_info()  # doctest: +SKIP
        {'id': '2de2b6da-69ee-11e6-ab6a-e82aea155996',
         'services': {},
         'type': 'Scheduler',
         'workers': {'127.0.0.1:40575': {'active': 0,
                                         'last-seen': 1472038237.4845693,
                                         'name': '127.0.0.1:40575',
                                         'services': {},
                                         'stored': 0,
                                         'time-delay': 0.0061032772064208984}}}
        (   RC   R  R   (   Ru   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   scheduler_info  s    c      	   C` s\   |  j  r t d   n	 | |  _  t |  j  d  # } t j |  j   | d d Wd QXd S(   s   Write the scheduler information to a json file.

        This facilitates easy sharing of scheduler information using a file
        system. The scheduler file can be used to instantiate a second Client
        using the same scheduler.

        Parameters
        ----------
        scheduler_file: str
            Path to a write the scheduler file.

        Examples
        --------
        >>> client = Client()  # doctest: +SKIP
        >>> client.write_scheduler_file('scheduler.json')  # doctest: +SKIP
        # connect to previous client's scheduler
        >>> client2 = Client(scheduler_file='scheduler.json')  # doctest: +SKIP
        s   Scheduler file already setR)  t   indenti   N(   R   RV  RS  RT  t   dumpRo  (   Ru   R   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   write_scheduler_file%  s
    		c         C` s@   t  | t t f  s! | f } n  |  j |  j j d | d | S(   s   Get arbitrary metadata from scheduler

        See set_metadata for the full docstring with examples

        Parameters
        ----------
        keys: key or list
            Key to access.  If a list then gets within a nested collection
        default: optional
            If the key does not exist then return this value instead.
            If not provided then this raises a KeyError if the key is not
            present

        See also
        --------
        Client.set_metadata
        Rg   R   (   R  RX   Rw  RC   R   t   get_metadata(   Ru   Rg   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRs  @  s    c         C` s   |  j  |  j j d | S(   s    Get logs from scheduler

        Parameters
        ----------
        n: int
            Number of logs to retrive.  Maxes out at 10000 by default,
            confiruable in config.yaml::log-length

        Returns
        -------
        Logs in reversed order (newest first)
        R  (   RC   R   t   logs(   Ru   R  (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   get_scheduler_logsV  s    c         C` s   |  j  |  j j d | d | S(   s   Get logs from workers

        Parameters
        ----------
        n: int
            Number of logs to retrive.  Maxes out at 10000 by default,
            confiruable in config.yaml::log-length
        workers: iterable
            List of worker addresses to retrive.  Gets all workers by default.

        Returns
        -------
        Dictionary mapping worker address to logs.
        Logs are returned in reversed order (newest first)
        R  R&  (   RC   R   t   worker_logs(   Ru   R  R&  (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   get_worker_logse  s    c         K` s"   |  j  |  j j d | d | | S(   s   Retire certain workers on the scheduler

        See dask.distributed.Scheduler.retire_workers for the full docstring.

        Examples
        --------
        You can get information about active workers using the following:
        >>> workers = client.scheduler_info()['workers']

        From that list you may want to select some workers to close
        >>> client.retire_workers(workers=['tcp://address:port', ...])

        See Also
        --------
        dask.distributed.Scheduler.retire_workers
        R&  t   close_workers(   RC   R   t   retire_workers(   Ru   R&  Rx  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRy  w  s
    c         C` s:   t  | t  s | f } n  |  j |  j j d | d | S(   sw   Set arbitrary metadata in the scheduler

        This allows you to store small amounts of data on the central scheduler
        process for administrative purposes.  Data should be msgpack
        serializable (ints, strings, lists, dicts)

        If the key corresponds to a task then that key will be cleaned up when
        the task is forgotten by the scheduler.

        If the key is a list then it will be assumed that you want to index
        into a nested dictionary structure using those keys.  For example if
        you call the following::

            >>> client.set_metadata(['a', 'b', 'c'], 123)

        Then this is the same as setting

            >>> scheduler.task_metadata['a']['b']['c'] = 123

        The lower level dictionaries will be created on demand.

        Examples
        --------
        >>> client.set_metadata('x', 123)  # doctest: +SKIP
        >>> client.get_metadata('x')  # doctest: +SKIP
        123

        >>> client.set_metadata(['x', 'y'], 123)  # doctest: +SKIP
        >>> client.get_metadata('x')  # doctest: +SKIP
        {'y': 123}

        >>> client.set_metadata(['x', 'w', 'z'], 456)  # doctest: +SKIP
        >>> client.get_metadata('x')  # doctest: +SKIP
        {'y': 123, 'w': {'z': 456}}

        >>> client.get_metadata(['x', 'w'])  # doctest: +SKIP
        {'z': 456}

        See Also
        --------
        get_metadata
        Rg   Rr  (   R  RX   RC   R   t   set_metadata(   Ru   Ri   Rr  (    (    s1   lib/python2.7/site-packages/distributed/client.pyRz    s    +c         ` s+  t  d |  } y" t |  j |  j j d | } Wn? t k
 rJ d } n) t k
 rr t |  j |  j j  } n Xt |  j |  j j d i d d 6| d 6} i | d 6| d 6| d 6} | r'd       | d  } d   | d  f g } | j	   f d	   t
 | j    D  t t  }	 xi | D]a \ }
 } xR | j   D]D \ } } | j | d
  } | | k rG|	 | j |
 | f  qGqGWq.W|	 r'g  } xf t
 |	 j    D]R \ } } d | | f g } | j	 |  | j d | t d d g |  f  qWt d d j |    q'n  | S(   s   Return version info for the scheduler, all workers and myself

        Parameters
        ----------
        check : boolean, default False
            raise ValueError if all required & optional packages
            do not match
        packages : List[str]
            Extra package names to check

        Examples
        --------
        >>> c.get_versions()  # doctest: +SKIP

        >>> c.get_versions(packages=['sklearn', 'geopandas'])  # doctest: +SKIP
        t   packagesRI  t   versionsRf   R   R&  Rh   c         S` s6   t  |  d j    } t t | t | d      S(   NR{  i    (   RX   R,  R   R+  R   (   R  R]   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   to_packages  s    c         3` s'   |  ] \ } } |   |  f Vq d  S(   N(    (   R(  R)  R  (   R}  (    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>  s    t   MISSINGs   %s
%sR   t   versions   Mismatched versions found

%ss   

N(   RT   RC   R   R   R|  Rc   R\   R   R  t   extendRW   R  R   RX   R   RH  RL   RV  R=  (   Ru   t   checkR{  Rh   R   R&  R   t   client_versionsR|  t
   mismatchedR  t   verst   pkgt   cvR  t   errst   rows(    (   R}  s1   lib/python2.7/site-packages/distributed/client.pyRT     s@    "		)"*c         C` s   t  | d |  S(   NRh   (   R  (   Ru   Ro   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s    c         O` s   t  d   d  S(   Ns%   Method moved to start_ipython_workers(   RK  (   Ru   R%  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   start_ipython  s    c         c` s]   | d  k r |  j j   V} n  |  j j d t d d  d |  V} t j | | f   d  S(   NRI  Rf   R  R&  (   R\   R   R'  R  R   R   R   (   Ru   R&  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _start_ipython_workers  s
    c         C` s  t  | t j t f  r% | g } n  t |  j |  j |  \ } } | r t  | t j  r d | k r g  t t |   D] } | j	 d t
 |   ^ qz } q | g } n  d t j k r d d l m } |   n  | r&d d l m } x7 t | |  D]# \ }	 }
 | |	 } | | |
  q Wn  | rd d l m } xU | j   D]D \ }	 } d |	 j	 d d	  j	 d
 d	  } | | d | d | qIWn  | S(   s   Start IPython kernels on workers

        Parameters
        ----------
        workers: list (optional)
            A list of worker addresses, defaults to all

        magic_names: str or list(str) (optional)
            If defined, register IPython magics with these names for
            executing code on the workers.  If string has asterix then expand
            asterix into 0, 1, ..., n for n workers

        qtconsole: bool (optional)
            If True, launch a Jupyter QtConsole connected to the worker(s).

        qtconsole_args: list(str) (optional)
            Additional arguments to pass to the qtconsole on startup.

        Examples
        --------
        >>> info = c.start_ipython_workers() # doctest: +SKIP
        >>> %remote info['192.168.1.101:5752'] worker.data  # doctest: +SKIP
        {'x': 1, 'y': 100}

        >>> c.start_ipython_workers('192.168.1.101:5752', magic_names='w') # doctest: +SKIP
        >>> %w worker.data  # doctest: +SKIP
        {'x': 1, 'y': 100}

        >>> c.start_ipython_workers('192.168.1.101:5752', qtconsole=True) # doctest: +SKIP

        Add asterix * in magic names to add one magic per worker

        >>> c.start_ipython_workers(magic_names='w_*') # doctest: +SKIP
        >>> %w_0 worker.data  # doctest: +SKIP
        {'x': 1, 'y': 100}
        >>> %w_1 worker.data  # doctest: +SKIP
        {'z': 5}

        Returns
        -------
        iter_connection_info: list
            List of connection_info dicts containing info necessary
            to connect Jupyter clients to the workers.

        See Also
        --------
        Client.start_ipython_scheduler: start ipython on the scheduler
        R9  t   IPythoni   (   t   register_remote_magic(   t   register_worker_magic(   t   connect_qtconsoles   dask-R3  R   t   /R  R1  (   R  R   R  R   RC   R   R  RR  R*  t   replaceR   t   syst   modulest   _ipython_utilsR  R  R  R  R  (   Ru   R&  t   magic_namest	   qtconsolet   qtconsole_argst	   info_dictR_  R  R  R   t
   magic_namet   connection_infoR  R  (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   start_ipython_workers  s*    3:

"t   scheduler_if_ipythonc   	      C` s   t  |  j |  j j  } | d k rs t } d t j k r[ d d l m } t	 |    } n  | rj d } qs d } n  | r d d l m } | | |  n  | r d d l m } | | d	 d
 d | n  | S(   s{   Start IPython kernel on the scheduler

        Parameters
        ----------
        magic_name: str or None (optional)
            If defined, register IPython magic with this name for
            executing code on the scheduler.
            If not defined, register %scheduler magic if IPython is running.

        qtconsole: bool (optional)
            If True, launch a Jupyter QtConsole connected to the worker(s).

        qtconsole_args: list(str) (optional)
            Additional arguments to pass to the qtconsole on startup.

        Examples
        --------
        >>> c.start_ipython_scheduler() # doctest: +SKIP
        >>> %scheduler scheduler.processing  # doctest: +SKIP
        {'127.0.0.1:3595': {'inc-1', 'inc-2'},
         '127.0.0.1:53589': {'inc-2', 'add-5'}}

        >>> c.start_ipython_scheduler(qtconsole=True) # doctest: +SKIP

        Returns
        -------
        connection_info: dict
            connection_info dict containing info necessary
            to connect Jupyter clients to the scheduler.

        See Also
        --------
        Client.start_ipython_workers: Start IPython on the workers
        R  R  i    (   t   get_ipythonR   i   (   R  (   R  R  s   dask-schedulerR1  N(   RC   R   R   R  Rj   R  R  R  R  t   boolR\   R  R  R  (	   Ru   R  R  R  R  t
   in_ipythonR  R  R  (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   start_ipython_scheduler^  s     %		c         c` so   t  | t  s | f } n  xM | D]E } t j |  r\ x- | j   D] } t |  VqD Wq" t |  Vq" Wd S(   ss   
        Expand a user-provided task key specification, e.g. in a resources
        or retries dictionary.
        N(   R  Rw  R   R)  R!  RG   (   R   R^   t   kkt   kkk(    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s    c         ` s    r4 t   t  r4   f d    j   D } n> t   t  r\  f d   | D } n t d t     t t |  S(   sp   
        Expand the user-provided "retries" specification
        to a {task key: Integral} dictionary.
        c         ` s5   i  |  ]+ \ } }   j  |  D] } | |  q q S(    (   R  (   R(  Ri   Rr  R  (   R   (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>  s   		c         ` s   i  |  ] }   |  q S(    (    (   R(  R  (   R  (    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>  s   	 s.   `retries` should be an integer or dict, got %r(   R  R   R  R   R   R   R   RG   (   R   R  R  R   (    (   R   R  s1   lib/python2.7/site-packages/distributed/client.pyR    s    c         ` s   t  | t  s( t d t |    n  i  } i  } t |  } xr | j   D]d \    t   t  r | j  f d   |  j    D  qM | j    f d   | D  qM W| r | r t d | f   n  | p | S(   s   
        Expand the user-provided "resources" specification
        to a {task key: {resource name: Number}} dictionary.
        s$   `resources` should be a dict, got %rc         3` s   |  ] } |   f Vq d  S(   N(    (   R(  R  (   R  (    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>  s    c         3` s"   |  ] } | i    6f Vq d  S(   N(    (   R(  R  (   R^   R  (    s1   lib/python2.7/site-packages/distributed/client.pys	   <genexpr>  s    sF   cannot have both per-key and all-key requirements in resources dict %r(	   R  R   R   R   RX   R  R  R  RV  (   R   R  R  t   per_key_reqst   global_reqs(    (   R^   R  s1   lib/python2.7/site-packages/distributed/client.pyR    s    	)$c         ` s1  t  | t t t f  r. i | t |  6} n  t  | t  r i  } x | j   D] \ }   t    t  rw   g   n  t j |  r t | j	    } n t d   t |  D  } | j
   f d   | D  qP Wn i  } | t k r t |  } n+ | r!t d   t |  D  } n g  } | | f S(   s1    Get restrictions from inputs to compute/persist c         S` s/   h  |  ]% } t  | j    D] } |  q q S(    (   R   R!  (   R(  R_   R^   (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <setcomp>  s   	 c         ` s   i  |  ] }   |  q S(    (    (   R(  R^   (   t   ws(    s1   lib/python2.7/site-packages/distributed/client.pys
   <dictcomp>  s   	 c         S` s)   h  |  ] } | j    D] } |  q q S(    (   R!  (   R(  R_   R^   (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <setcomp>  s   	 (   R  R   Rw  RX   R   R  R   R)  R   R!  R  RZ   (   R   R-  R&  R  R  t   collsRg   R  (    (   R  s1   lib/python2.7/site-packages/distributed/client.pyR,    s(    $c         O` s   t  |  | |  S(   N(   R   (   R-  R%  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR     s    s   task-stream.htmlc         C` s.   |  j  |  j d | d | d | d | d | S(   s   Get task stream data from scheduler

        This collects the data present in the diagnostic "Task Stream" plot on
        the dashboard.  It includes the start, stop, transfer, and
        deserialization time of every task for a particular duration.

        Note that the task stream diagnostic does not run by default.  You may
        wish to call this function once before you start work to ensure that
        things start recording, and then again after you have completed.

        Parameters
        ----------
        start: Number or string
            When you want to start recording
            If a number it should be the result of calling time()
            If a string then it should be a time difference before now,
            like '60s' or '500 ms'
        stop: Number or string
            When you want to stop recording
        count: int
            The number of desired records, ignored if both start and stop are
            specified
        plot: boolean, str
            If true then also return a Bokeh figure
            If plot == 'save' then save the figure to a file
        filename: str (optional)
            The filename to save to if you set ``plot='save'``

        Examples
        --------
        >>> client.get_task_stream()  # prime plugin if not already connected
        >>> x.compute()  # do some work
        >>> client.get_task_stream()
        [{'task': ...,
          'type': ...,
          'thread': ...,
          ...}]

        Pass the ``plot=True`` or ``plot='save'`` keywords to get back a Bokeh
        figure

        >>> data, figure = client.get_task_stream(plot='save', filename='myfile.html')

        Alternatively consider the context manager

        >>> from dask.distributed import get_task_stream
        >>> with get_task_stream() as ts:
        ...     x.compute()
        >>> ts.data
        [...]

        Returns
        -------
        L: List[Dict]

        See Also
        --------
        get_task_stream: a context manager version of this method
        R  R~  t   countRc  RP  (   RC   t   _get_task_stream(   Ru   R  R~  R  Rc  RP  (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   get_task_stream  s    >	c         c` s   |  j  j d | d | d |  V} | r d d l m } | |  } d d l m }	 |	 d d  \ }
 } |
 j j |  | d	 k r d
 d l m	 } | | d d d | n  t
 j | | f   n t
 j |   d  S(   NR  R~  R  i   (   t
   rectangles(   t   task_stream_figureRf  Rg  Rh  i    (   Rh  Ri  s   Dask Task StreamRP  (   R   R  t   diagnostics.task_streamR  t   bokeh.componentsR  R  R  Rl  Rh  R   R   (   Ru   R  R~  R  Rc  RP  Rx  R  t   rectsR  Rn  Rm  Rh  (    (    s1   lib/python2.7/site-packages/distributed/client.pyR  E  s    "c         c` s   |  j  j d t |   V} i  } xa | j   D]S \ } } | d d k r\ | d | | <q/ | d d k r/ t j t |     q/ q/ Wt j |   d  S(   Nt   setupR[   R  R   R   (	   R   t   register_worker_callbacksR7   R  R   R   R1   R   R   (   Ru   R  R   R  Ri   R  (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _register_worker_callbacksZ  s    c         C` s   |  j  |  j d | S(   s  
        Registers a setup callback function for all current and future workers.

        This registers a new setup function for workers in this cluster. The
        function will run immediately on all currently connected workers. It
        will also be run upon connection by any workers that are added in the
        future. Multiple setup functions can be registered - these will be
        called in the order they were added.

        If the function takes an input argument named ``dask_worker`` then
        that variable will be populated with the worker itself.

        Parameters
        ----------
        setup : callable(dask_worker: Worker) -> None
            Function to register and run on all workers
        R  (   RC   R  (   Ru   R  (    (    s1   lib/python2.7/site-packages/distributed/client.pyR  e  s    N(y   R   R   R   R\   RN   RZ   Rj   t   DEFAULT_EXTENSIONSRz   t   classmethodR  R   R   RC   R   R   R  R   RJ  Rr   R   R   RC  Rh  R\  R  R  Rp  Rq  Rs  Ru  R   Rl   R   Rv  R]  R  R  R  R  R  R  R  Re  t	   _shutdownRt  R  R  R   R  R  R   R  R  R  R  R  R  R  R   R  R   R  R  R  R  R  R  R  R  R  R  R  R  R   R  R%  R4  R7  RK  RL  RM  R   RS  RJ  RO  R[  RZ  R  R]  R'  R  R^  R_  R  Ra  Re  Rd  Ro  Rr  Rs  Ru  Rw  Ry  Rz  RT   R  R  R  R  R  R  R  R  R,  t   staticmethodR   R  R  R  R  (    (    (    s1   lib/python2.7/site-packages/distributed/client.pyR     sz  F|			D			
		I1								-	D$				e		e!	Ie	m
	0		
		 	9	!^@		"Y			-!"%!			/>		R:	F
t   Executorc           B` s   e  Z d  Z d   Z RS(   s    Deprecated: see Client c         O` s*   t  j d  t t |   j | |   d  S(   Ns#   Executor has been renamed to Client(   R  R  R  R  Rz   (   Ru   R%  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRz   }  s    (   R   R   R   Rz   (    (    (    s1   lib/python2.7/site-packages/distributed/client.pyR  z  s   c          O` s   t  d   d  S(   Ns7   This has been moved to the Client.get_executor() method(   RK  (   R%  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   CompatibleExecutor  s    t   ALL_COMPLETEDt   FIRST_COMPLETEDc   	      c` s/  | d  k	 r+ t | t  r+ t d   n  t |   }  | t k rL t } n! | t k ra t } n t	 d   | d   |  D  } | d  k	 r t
 j t d |  |  } n  | Vd   |  D d   |  D } } g  | D] } | j d k r | j ^ q } | rt |   n  t
 j t | |    d  S(   Ns   timeout= keyword received a non-numeric value.
Beware that wait expects a list of values
  Bad:  wait(x, y, z)
  Good: wait([x, y, z])sD   Only return_when='ALL_COMPLETED' and 'FIRST_COMPLETED' are supportedc         S` s   h  |  ] } | j  j    q S(    (   Rp   R   (   R(  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <setcomp>  s   	 R   c         S` s%   h  |  ] } | j  d  k r |  q S(   R   (   R[   (   R(  t   fu(    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <setcomp>  s   	 c         S` s%   h  |  ] } | j  d  k r |  q S(   R   (   R[   (   R(  R  (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <setcomp>  s   	 R   (   R\   R  R   R   R  R  RB   R  RS   R  R   R#  R   R[   Ri   R   R   R   (	   t   fsR   t   return_whent   wait_forR   R|   t   not_doneR   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRY    s(    			+c         C` s+   t    } | j t |  d | d | } | S(   s   Wait until all/any futures are finished

    Parameters
    ----------
    fs: list of futures
    timeout: number, optional
        Time in seconds after which to raise a ``dask.distributed.TimeoutError``
    -------
    Named tuple of completed, not completed
    R   R  (   R  RC   RY  (   R  R   R  Rh   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR     s    	c         c` s   t  |   }  t d   |   } g  | j   D] } | d ^ q+ } t j g  | D] } | j j   ^ qN   } xM | j   s | j   V| | j	 } x" | | j
 D] } | j |  q Wqo Wd  S(   Nc         S` s   |  j  S(   N(   Ri   (   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR     R   i    (   R  R   R,  R   t   WaitIteratorRp   R   R|   R  t   current_indexRi   t
   put_nowait(   R  t   queuet   groupsR  t   firstsR   t   wait_iteratorR   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _as_completed  s    #+c         c` s7   t    } t |  |  V| j   V} t j |   d S(   sK    Return a single completed future

    See Also:
        _as_completed
    N(   R"   R  R   R   R   (   Ro   R  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _first_completed  s    	t   as_completedc           B` s   e  Z d  Z d d e e d  Z d   Z e j	 d    Z
 d   Z d   Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z e j	 d    Z e Z e d  Z d   Z RS(   s  
    Return futures in the order in which they complete

    This returns an iterator that yields the input future objects in the order
    in which they complete.  Calling ``next`` on the iterator will block until
    the next future completes, irrespective of order.

    Additionally, you can also add more futures to this object during
    computation with the ``.add`` method

    Parameters
    ----------
    futures: Collection of futures
        A list of Future objects to be iterated over in the order in which they
        complete
    with_results: bool (False)
        Whether to wait and include results of futures as well;
        in this case `as_completed` yields a tuple of (future, result)
    raise_errors: bool (True)
        Whether we should raise when the result of a future raises an exception;
        only affects behavior when `with_results=True`.

    Examples
    --------
    >>> x, y, z = client.map(inc, [1, 2, 3])  # doctest: +SKIP
    >>> for future in as_completed([x, y, z]):  # doctest: +SKIP
    ...     print(future.result())  # doctest: +SKIP
    3
    2
    4

    Add more futures during computation

    >>> x, y, z = client.map(inc, [1, 2, 3])  # doctest: +SKIP
    >>> ac = as_completed([x, y, z])  # doctest: +SKIP
    >>> for future in ac:  # doctest: +SKIP
    ...     print(future.result())  # doctest: +SKIP
    ...     if random.random() < 0.5:  # doctest: +SKIP
    ...         ac.add(c.submit(double, future))  # doctest: +SKIP
    4
    2
    8
    3
    6
    12
    24

    Optionally wait until the result has been gathered as well

    >>> ac = as_completed([x, y, z], with_results=True)  # doctest: +SKIP
    >>> for future, result in ac:  # doctest: +SKIP
    ...     print(result)  # doctest: +SKIP
    2
    4
    3
    c         C` s   | d  k r g  } n  t d    |  _ t   |  _ t j   |  _ | pQ t   j	 |  _	 t
   |  _ t j
   |  _ | |  _ | |  _ | r |  j |  n  d  S(   Nc           S` s   d S(   Ni    (    (    (    (    s1   lib/python2.7/site-packages/distributed/client.pyR     R   (   R\   R   Ro   R  R  R   t   Lockt   lockR  R   R   t	   conditiont   thread_conditiont   with_resultst   raise_errorsR  (   Ru   Ro   R   R  R  (    (    s1   lib/python2.7/site-packages/distributed/client.pyRz     s    			c         C` s.   |  j  j   |  j  |  j j   Wd  QXd  S(   N(   R  t   notifyR  (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _notify"  s    
c         c` s   y t  |  VWn t k
 r" n X|  j rB | j d t  V} n  |  j n |  j | c d 8<|  j | sy |  j | =n  |  j r |  j j | | f  n |  j j |  |  j	   Wd  QXd  S(   NR~   i   (
   RY  R   R  R   Rj   R  Ro   R  R  R  (   Ru   R   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _track_future'  s    	
	c      	   C` sp   |  j  a xY | D]Q } t | t  s9 t d |   n  |  j | c d 7<|  j j |  j |  q WWd QXd S(   sp    Add multiple futures to the collection.

        The added futures will emit from the iterator once they finishs   Input must be a future, got %si   N(   R  R  Re   R   Ro   R   R   R  (   Ru   Ro   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR  9  s    
c         C` s   |  j  | f  d S(   sj    Add a future to the collection

        This future will emit from the iterator once it finishes
        N(   R  (   Ru   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR  D  s    c         C` s   |  j    S(   s7   Returns True if there no completed or computing futures(   R  (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   is_emptyK  s    c         C` s   |  j  j   S(   s6   Returns True if there are completed futures available.(   R  R  (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt	   has_readyO  s    c         C` s1   |  j  " t |  j  t |  j j  SWd QXd S(   s    Return the number of futures yet to be returned

        This includes both the number of futures still computing, as well as
        those that are finished, but have not yet been returned from this
        iterator.
        N(   R  R*  Ro   R  (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR  S  s    
c         C` s   |  S(   N(    (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   __iter__]  s    c         C` s   |  S(   N(    (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt	   __aiter__`  s    c         C` sS   |  j  j   } |  j rO | \ } } |  j rO | j d k rO t j |   qO n  | S(   NR   (   R  R   R  R  R[   R   R   (   Ru   t   resR   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _get_and_raisec  s    	c         C` s[   xN |  j  j   rP |  j   r* t    n  |  j  |  j j d d  Wd  QXq W|  j   S(   NR   g?(   R  R  R  R  R  R   R  (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   __next__k  s    
c         c` sq   |  j  r" |  j j   r" t  n  x3 |  j j   rW |  j  sF t  n  |  j j   Vq% Wt j |  j     d  S(   N(	   Ro   R  R  R-   R  R   R   R   R  (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt	   __anext__s  s    			c         C` sN   | r t  |   g } n g  } x) |  j j   sI | j |  j j    q! W| S(   sY   Get the next batch of completed futures.

        Parameters
        ----------
        block: bool, optional
            If True then wait until we have some result, otherwise return
            immediately, even with an empty list.  Defaults to True.

        Examples
        --------
        >>> ac = as_completed(futures)  # doctest: +SKIP
        >>> client.gather(ac.next_batch())  # doctest: +SKIP
        [4, 1, 3]

        >>> client.gather(ac.next_batch(block=False))  # doctest: +SKIP
        []

        Returns
        -------
        List of futures or (future, result) tuples
        (   R  R  R  RH  R   (   Ru   t   blockt   batch(    (    s1   lib/python2.7/site-packages/distributed/client.pyt
   next_batch  s    c         c` s;   x4 t  r6 y |  j d t   VWq t k
 r2 d SXq Wd S(   s3  
        Yield all finished futures at once rather than one-by-one

        This returns an iterator of lists of futures or lists of
        (future, result) tuples rather than individual futures or individual
        (future, result) tuples.  It will yield these as soon as possible
        without waiting.

        Examples
        --------
        >>> for batch in as_completed(futures).batches():  # doctest: +SKIP
        ...     results = client.gather(batch)
        ...     print(results)
        [4, 2]
        [1, 3, 7]
        [5]
        [6]
        R  N(   RZ   R  R  (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   batches  s
    	N(   R   R   R   R\   Rj   RZ   Rz   R  R   R   R  R  R  R  R  R  R  R  R  R  R  R  R  R  (    (    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s"   8						
				c          O` s   t  d   d  S(   Ns   This has moved to as_completed(   RK  (   R%  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   AsCompleted  s    c         C` s)   |  p t    }  |  r |  St d   d S(   s$    Return a client if one has started s   No clients found
Start an client and point it to the scheduler address
  from distributed import Client
  client = Client('ip-addr-of-scheduler:8786')
N(   R`   RV  (   R_   (    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s
    c         C` s!   t  j j d d  t |   d  S(   NR   s   dask.distributed(   R   R   R   Rb   (   Rh   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   ensure_default_get  s    c         C` sO   d d l  m } t |  |  r/ | |  j |  St j |   } | | _ | Sd  S(   Ni    (   t   Delayed(   t   dask.delayedR  R  Ri   t   copyR   (   R_   R  R  t   cc(    (    s1   lib/python2.7/site-packages/distributed/client.pyR"    s    	c         C` s1  |  g } t    } x | r | j   } t |  t t  t f k rR | j |  q t |  t k rz | j | j    q t |  t k r | j | j	 j    q t
 | t  r | j |  q t j |  r | j | j   j    q q W| d k	 r'd   | D } | r't |   q'n  t |  S(   s     Future objects in a collection c         S` s"   h  |  ] } | j    r |  q S(    (   R   (   R(  R   (    (    s1   lib/python2.7/site-packages/distributed/client.pys	   <setcomp>  s   	 N(   R   R!  R   Rw  RX   R  R   R,  R   R  R  Re   R  R   R)  R   R\   R   (   t   oRh   t   stackRo   R  t   bad(    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s&    			 c         C` sR   t  |   } x? | D]7 } | j j i d d 6t | j  g d 6d d 6 q Wd S(   sn   Run tasks at least once, even if we release the futures

    Under normal operation Dask will not run any tasks for which there is not
    an active future (this avoids unnecessary work in many situations).
    However sometimes you want to just fire off a task, not track its future,
    and expect it to finish eventually.  You can use this function on a future
    or collection of futures to ask Dask to complete the task even if no active
    client is tracking it.

    The results will not be kept in memory after the task completes (unless
    there is an active future) so this is only useful for tasks that depend on
    side effects.

    Parameters
    ----------
    obj: Future, list, dict, dask collection
        The futures that you want to run at least once

    Examples
    --------
    >>> fire_and_forget(client.submit(func, *args))  # doctest: +SKIP
    s   client-desires-keysRf   Rg   s   fire-and-forgetRh   N(   R  Rh   Rr   RG   Ri   (   t   objRo   R   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   fire_and_forget  s    	R  c           B` sV   e  Z d  Z d e d d  Z d   Z d   Z e j	 d    Z
 e j	 d    Z RS(   s  
    Collect task stream within a context block

    This provides diagnostic information about every task that was run during
    the time when this block was active.

    This must be used as a context manager.

    Parameters
    ----------
    plot: boolean, str
        If true then also return a Bokeh figure
        If plot == 'save' then save the figure to a file
    filename: str (optional)
        The filename to save to if you set ``plot='save'``

    Examples
    --------
    >>> with get_task_stream() as ts:
    ...     x.compute()
    >>> ts.data
    [...]

    Get back a Bokeh figure and optionally save to a file

    >>> with get_task_stream(plot='save', filename='task-stream.html') as ts:
    ...    x.compute()
    >>> ts.figure
    <Bokeh Figure>

    To share this file with others you may wish to upload and serve it online.
    A common way to do this is to upload the file as a gist, and then serve it
    on https://rawgit.com ::

       $ pip install gist
       $ gist task-stream.html
       https://gist.github.com/8a5b3c74b10b413f612bb5e250856ceb

    You can then navigate to that site, click the "Raw" button to the right of
    the ``task-stream.html`` file, and then provide that URL to
    https://rawgit.com .  This process should provide a sharable link that
    others can use to see your task stream plot.

    See Also
    --------
    Client.get_task_stream: Function version of this context manager
    s   task-stream.htmlc         C` sS   g  |  _  | |  _ | |  _ d  |  _ | p0 t   |  _ |  j j d d d d  d  S(   NR  i    R~  (   R  t   _plott	   _filenameR\   Rm  R  Rh   R  (   Ru   Rh   Rc  RP  (    (    s1   lib/python2.7/site-packages/distributed/client.pyRz   F  s    				c         C` s   t    |  _ |  S(   N(   R4   R  (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRp  N  s    c         C` sY   |  j  j d |  j d |  j d |  j  } |  j rE | \ } |  _ n  |  j j |  d  S(   NR  Rc  RP  (   Rh   R  R  R  R  Rm  R  R  (   Ru   R   Rr  R   R]   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRu  R  s
    	c         C` s   t  j |    d  S(   N(   R   R   (   Ru   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRq  Z  s    c         c` sZ   |  j  j d |  j d |  j d |  j  V} |  j rF | \ } |  _ n  |  j j |  d  S(   NR  Rc  RP  (   Rh   R  R  R  R  Rm  R  R  (   Ru   R   Rr  R   R]   (    (    s1   lib/python2.7/site-packages/distributed/client.pyRs  ^  s
    	N(   R   R   R   R\   Rj   Rz   Rp  Ru  R   R   Rq  Rs  (    (    (    s1   lib/python2.7/site-packages/distributed/client.pyR    s   /		c         c` s.   t    } t |   z	 d VWd t |  Xd S(   s    Set the default client for the duration of the context

    Parameters
    ----------
    c : Client
        This is what default_client() will return within the with-block.
    N(   R  Rb   (   R_   t   old_exec(    (    s1   lib/python2.7/site-packages/distributed/client.pyR  h  s
    		
	c          C` s5   t    }  |  d k	 r1 t |  _ |  j d d  n  d S(   s}   
    Force close of global client.  This cleans up when a client
    wasn't close explicitly, e.g. interactive sessions.
    R   i   N(   R`   R\   Rj   R  Rt  (   R_   (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   _close_global_clienty  s    		(   t
   __future__R    R   R   t   atexitR-  R   t   concurrent.futuresR   t   concurrent.futures._baseR   R   t
   contextlibR   R  t   datetimeR   RZ  t	   functoolsR	   R
   R  RT  t   loggingt   numbersR   R   R   R  R   R   R   RY  R  t   weakrefR   t	   dask.baseR   R   R   t	   dask.coreR   R   t   dask.optimizationR   t   dask.compatibilityR   R   t
   dask.utilsR   t   cytoolzR   R   R   R   R   t   ImportErrort   toolzR  R   t   tornadoR   t   tornado.genR   t   tornado.locksR   R   R    t   tornado.ioloopR!   t   tornado.queuesR"   t   batchedR#   t
   utils_commR$   R%   R&   R'   R(   t
   cfexecutorR)   t   compatibilityR  R*   R+   R,   R-   R.   t   coreR/   R0   R1   R2   R3   t   metricsR4   t   nodeR5   R=  R6   t   protocol.pickleR7   R8   t   publishR9   t   pubsubR:   R   R;   R<   t   threadpoolexecutorR=   R   R>   R?   R@   RA   t   utilsRB   RC   RD   RE   RF   RG   RH   RI   RJ   RK   RL   RM   RN   RO   RP   RQ   RR   RS   R|  RT   t	   getLoggerR   R   t   WeakValueDictionaryRY   Ra   R  R`   Rb   Rd   Re   t   objectRq   R   R   t   registerR   RK  R   R   R  R  R  R  R\   RY  R   R  R  R  R  R  R  R"  R  R  R  R  R  (    (    (    s1   lib/python2.7/site-packages/distributed/client.pyt   <module>   s   ,,
(.("v						 %@             	"				"S	