σ
ίΘ[c           @` s}   d  Z  d d l m Z m Z m Z m Z d d l m Z d d l m	 Z	 d g Z
 e	 d d d	 d
 e f d     Y Z d S(   u!   Asynchronous VO service requests.i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsi   (   t   ThreadPoolExecutor(   t
   deprecatedu	   AsyncBaseu   2.0t   alternativeu+   astroquery.vo_conesearch.vo_async.AsyncBaset	   AsyncBasec           B` s,   e  Z d  Z d   Z d   Z d d  Z RS(   uT  Base class for asynchronous VO service requests
    using :py:class:`concurrent.futures.ThreadPoolExecutor`.

    Service request will be forced to run in silent
    mode by setting ``verbose=False``. Warnings are controlled
    by :py:mod:`warnings` module.

    .. note::

        Methods of the attributes can be accessed directly,
        with priority given to ``executor``.

    Parameters
    ----------
    func : function
        The function to run.

    args, kwargs
        Arguments and keywords accepted by the service request
        function to be called asynchronously.

    Attributes
    ----------
    executor : :py:class:`concurrent.futures.ThreadPoolExecutor`
        Executor running the function on single thread.

    future : :py:class:`concurrent.futures.Future`
        Asynchronous execution created by ``executor``.

    c         O` s8   t  | d <t d  |  _ |  j j | | |  |  _ d  S(   Nu   verbosei   (   t   FalseR   t   executort   submitt   future(   t   selft   funct   argst   kwargs(    (    s9   lib/python2.7/site-packages/astropy/vo/client/vo_async.pyt   __init__.   s    
c         C` s9   y t  |  j |  SWn t k
 r4 t  |  j |  SXd S(   u+   Expose ``executor`` and ``future`` methods.N(   t   getattrR	   t   AttributeErrorR   (   R   t   what(    (    s9   lib/python2.7/site-packages/astropy/vo/client/vo_async.pyt   __getattr__3   s    c         C` sZ   z? y |  j  j d |  } Wn t k
 r= } t } |  n XWd |  j j d t  | SX(   uπ  Get result, if available, then shut down thread.

        Parameters
        ----------
        timeout : int or float
            Wait the given amount of time in seconds before
            obtaining result. If not given, wait indefinitely
            until function is done.

        Returns
        -------
        result
            Result returned by the function.

        Raises
        ------
        Exception
            Errors raised by :py:class:`concurrent.futures.Future`.

        t   timeoutNt   wait(   R   t   resultt	   Exceptiont   NoneR	   t   shutdownR   (   R   R   R   t   e(    (    s9   lib/python2.7/site-packages/astropy/vo/client/vo_async.pyt   get:   s     N(   t   __name__t
   __module__t   __doc__R   R   R   R   (    (    (    s9   lib/python2.7/site-packages/astropy/vo/client/vo_async.pyR      s    		N(   R   t
   __future__R    R   R   R   t   utils.compat.futuresR   t   utils.decoratorsR   t   __all__t   objectR   (    (    (    s9   lib/python2.7/site-packages/astropy/vo/client/vo_async.pyt   <module>   s   "	