ó
ßüÚ\c           @` sŒ   d  d l  m Z m Z m Z d  d l m Z d  d l Z d d l m Z m	 Z	 d d l
 m Z m Z m Z e d e d „ ƒ Z d	 „  Z d S(
   i    (   t   print_functiont   divisiont   absolute_import(   t   contextmanagerNi   (   t   secedet   rejoin(   t   thread_statet
   get_clientt
   get_workeri   c         c` s]   t  ƒ  } t d |  ƒ } | rD t ƒ  | j j | j t j d ƒ n  | V| rY t ƒ  n  d S(   s¯   Get client for this thread

    This context manager is intended to be called within functions that we run
    on workers.  When run as a context manager it delivers a client
    ``Client`` object that can submit other tasks directly from that worker.

    Parameters
    ----------
    timeout: Number
        Timeout after which to err
    separate_thread: bool, optional
        Whether to run this function outside of the normal thread pool
        defaults to True

    Examples
    --------
    >>> def func(x):
    ...     with worker_client() as c:  # connect from worker back to scheduler
    ...         a = c.submit(inc, x)     # this task can submit more tasks
    ...         b = c.submit(dec, x)
    ...         result = c.gather([a, b])  # and gather results
    ...     return result

    >>> future = client.submit(func, 1)  # submit func(1) on cluster

    See Also
    --------
    get_worker
    get_client
    secede
    t   timeouts   long-runningN(	   R   R   R   t   loopt   add_callbackt
   transitionR   t   keyR   (   R	   t   separate_threadt   workert   client(    (    s8   lib/python2.7/site-packages/distributed/worker_client.pyt   worker_client
   s    !	c          O` s   t  j d ƒ t |  | Ž  S(   Ns'   local_client has moved to worker_client(   t   warningst   warnR   (   t   argst   kwargs(    (    s8   lib/python2.7/site-packages/distributed/worker_client.pyt   local_client7   s    (   t
   __future__R    R   R   t
   contextlibR   R   t   threadpoolexecutorR   R   R   R   R   R   t   TrueR   R   (    (    (    s8   lib/python2.7/site-packages/distributed/worker_client.pyt   <module>   s   ,