B
    F.\                 @   sf   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d	d
Zdd ZdS )    )print_functiondivisionabsolute_import)contextmanagerN   )secederejoin)thread_state
get_client
get_worker   Tc             c   sB   t  }t| d}|r.t  |j|jtjd |V  |r>t  dS )a   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
    )timeoutzlong-runningN)	r   r
   r   ZloopZadd_callbackZ
transitionr	   keyr   )r   Zseparate_threadworkerZclient r   8lib/python3.7/site-packages/distributed/worker_client.pyworker_client
   s    !
r   c              O   s   t d t| |S )Nz'local_client has moved to worker_client)warningswarnr   )argskwargsr   r   r   local_client7   s    
r   )r   T)Z
__future__r   r   r   
contextlibr   r   Zthreadpoolexecutorr   r   r   r	   r
   r   r   r   r   r   r   r   <module>   s   ,