ok

Mini Shell

Direktori : /opt/alt/python35/lib64/python3.5/concurrent/futures/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/concurrent/futures/__pycache__/_base.cpython-35.pyc



J�Ma:N�
@s�dZddlZddlZddlZddlZdZdZdZdZdZ	dZ
d	Zd
ZdZ
e	e
eee
gZe	de
d
edede
diZejd�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd �d e�Zd!d"�Zdd#d$�Zejd%d&�Zded'd(�Z Gd)d*�d*e�Z!Gd+d,�d,e�Z"dS)-z"Brian Quinlan (brian@sweetapp.com)�N�FIRST_COMPLETED�FIRST_EXCEPTION�
ALL_COMPLETED�
_AS_COMPLETED�PENDING�RUNNING�	CANCELLED�CANCELLED_AND_NOTIFIED�FINISHED�pending�running�	cancelled�finishedzconcurrent.futuresc@seZdZdZdS)�Errorz-Base class for all future-related exceptions.N)�__name__�
__module__�__qualname__�__doc__�rr�=/opt/alt/python35/lib64/python3.5/concurrent/futures/_base.pyr,src@seZdZdZdS)�CancelledErrorzThe Future was cancelled.N)rrrrrrrrr0src@seZdZdZdS)�TimeoutErrorz*The operation exceeded the given deadline.N)rrrrrrrrr4src@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�_Waiterz;Provides the event that wait() and as_completed() block on.cCstj�|_g|_dS)N)�	threadingZEvent�event�finished_futures)�selfrrr�__init__:sz_Waiter.__init__cCs|jj|�dS)N)r�append)r�futurerrr�
add_result>sz_Waiter.add_resultcCs|jj|�dS)N)rr)rrrrr�
add_exceptionAsz_Waiter.add_exceptioncCs|jj|�dS)N)rr)rrrrr�
add_cancelledDsz_Waiter.add_cancelledN)rrrrrr r!r"rrrrr8s
rcs^eZdZdZ�fdd�Z�fdd�Z�fdd�Z�fdd	�Z�S)
�_AsCompletedWaiterzUsed by as_completed().cs&tt|�j�tj�|_dS)N)�superr#rr�Lock�lock)r)�	__class__rrrJsz_AsCompletedWaiter.__init__c
s8|j�(tt|�j|�|jj�WdQRXdS)N)r&r$r#r r�set)rr)r'rrr Ns
z_AsCompletedWaiter.add_resultc
s8|j�(tt|�j|�|jj�WdQRXdS)N)r&r$r#r!rr()rr)r'rrr!Ss
z _AsCompletedWaiter.add_exceptionc
s8|j�(tt|�j|�|jj�WdQRXdS)N)r&r$r#r"rr()rr)r'rrr"Xs
z _AsCompletedWaiter.add_cancelled)rrrrrr r!r"rr)r'rr#Gs
r#csLeZdZdZ�fdd�Z�fdd�Z�fdd�Z�S)�_FirstCompletedWaiterz*Used by wait(return_when=FIRST_COMPLETED).cs!t�j|�|jj�dS)N)r$r rr()rr)r'rrr `sz _FirstCompletedWaiter.add_resultcs!t�j|�|jj�dS)N)r$r!rr()rr)r'rrr!dsz#_FirstCompletedWaiter.add_exceptioncs!t�j|�|jj�dS)N)r$r"rr()rr)r'rrr"hsz#_FirstCompletedWaiter.add_cancelled)rrrrr r!r"rr)r'rr)]sr)csjeZdZdZ�fdd�Zdd�Z�fdd�Z�fdd	�Z�fd
d�Z�S)�_AllCompletedWaiterz<Used by wait(return_when=FIRST_EXCEPTION and ALL_COMPLETED).cs2||_||_tj�|_t�j�dS)N)�num_pending_calls�stop_on_exceptionrr%r&r$r)rr+r,)r'rrros		z_AllCompletedWaiter.__init__c
Cs:|j�*|jd8_|js/|jj�WdQRXdS)N�)r&r+rr()rrrr�_decrement_pending_callsus
	z,_AllCompletedWaiter._decrement_pending_callscst�j|�|j�dS)N)r$r r.)rr)r'rrr {sz_AllCompletedWaiter.add_resultcs7t�j|�|jr)|jj�n
|j�dS)N)r$r!r,rr(r.)rr)r'rrr!s	z!_AllCompletedWaiter.add_exceptioncst�j|�|j�dS)N)r$r"r.)rr)r'rrr"�sz!_AllCompletedWaiter.add_cancelled)	rrrrrr.r r!r"rr)r'rr*lsr*c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�_AcquireFutureszDA context manager that does an ordered acquire of Future conditions.cCst|dt�|_dS)N�key)�sorted�id�futures)rr3rrrr�sz_AcquireFutures.__init__cCs%x|jD]}|jj�q
WdS)N)r3�
_condition�acquire)rrrrr�	__enter__�sz_AcquireFutures.__enter__cGs%x|jD]}|jj�q
WdS)N)r3r4�release)r�argsrrrr�__exit__�sz_AcquireFutures.__exit__N)rrrrrr6r9rrrrr/�sr/cCs�|tkrt�}n�|tkr0t�}nktdd�|D��}|tkrjt|dd�}n1|tkr�t|dd�}ntd|��x|D]}|j	j
|�q�W|S)Ncss$|]}|jttgkVqdS)N)�_stater	r
)�.0�frrr�	<genexpr>�sz._create_and_install_waiters.<locals>.<genexpr>r,TFzInvalid return condition: %r)rr#rr)�sumrr*r�
ValueError�_waitersr)�fs�return_when�waiterZ
pending_countr<rrr�_create_and_install_waiters�s
rDc	csx|dk	r|tj�}t|�}t|��7tdd�|D��}||}t|t�}WdQRXz�|EdHx�|r<|dkr�d}n>|tj�}|dkr�tdt|�t|�f��|jj|�|j	�$|j
}g|_
|jj�WdQRXx |D]}|V|j|�qWq}WWdx/|D]'}|j
�|jj|�WdQRXqHWXdS)anAn iterator over the given futures that yields each as it completes.

    Args:
        fs: The sequence of Futures (possibly created by different Executors) to
            iterate over.
        timeout: The maximum number of seconds to wait. If None, then there
            is no limit on the wait time.

    Returns:
        An iterator that yields the given Futures as they complete (finished or
        cancelled). If any given Futures are duplicated, they will be returned
        once.

    Raises:
        TimeoutError: If the entire result iterator could not be generated
            before the given timeout.
    Ncss*|] }|jttgkr|VqdS)N)r:r	r
)r;r<rrrr=�szas_completed.<locals>.<genexpr>rz%d (of %d) futures unfinished)�timer(r/rDrr�lenr�waitr&r�clear�remover4r@)	rA�timeout�end_timerrrCZwait_timeoutrr<rrr�as_completed�s:

			
		


rL�DoneAndNotDoneFuturesz
done not_donecCs1t|���tdd�|D��}t|�|}|tkrU|rUt||�S|tkr�|r�tdd�|D��r�t||�St|�t|�kr�t||�St||�}WdQRX|jj	|�x/|D]'}|j
�|jj|�WdQRXq�W|j
|j�t|t|�|�S)aWait for the futures in the given sequence to complete.

    Args:
        fs: The sequence of Futures (possibly created by different Executors) to
            wait upon.
        timeout: The maximum number of seconds to wait. If None, then there
            is no limit on the wait time.
        return_when: Indicates when this function should return. The options
            are:

            FIRST_COMPLETED - Return when any future finishes or is
                              cancelled.
            FIRST_EXCEPTION - Return when any future finishes by raising an
                              exception. If no future raises an exception
                              then it is equivalent to ALL_COMPLETED.
            ALL_COMPLETED -   Return when all futures finish or are cancelled.

    Returns:
        A named 2-tuple of sets. The first set, named 'done', contains the
        futures that completed (is finished or cancelled) before the wait
        completed. The second set, named 'not_done', contains uncompleted
        futures.
    css*|] }|jttgkr|VqdS)N)r:r	r
)r;r<rrrr=szwait.<locals>.<genexpr>css4|]*}|j�r|j�dk	r|VqdS)N)r
�	exception)r;r<rrrr=	sN)r/r(rrMr�anyrFrDrrGr4r@rI�updater)rArJrB�doneZnot_donerCr<rrrrG�s"





rGc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zddd�Z
ddd�Zdd�Zdd�Zdd�ZdS)�Futurez5Represents the result of an asynchronous computation.cCs@tj�|_t|_d|_d|_g|_g|_dS)z8Initializes the future. Should not be called by clients.N)	rZ	Conditionr4rr:�_result�
_exceptionr@�_done_callbacks)rrrrrs				zFuture.__init__cCsKxD|jD]9}y||�Wq
tk
rBtjd|�Yq
Xq
WdS)Nz!exception calling callback for %r)rU�	Exception�LOGGERrN)r�callbackrrr�_invoke_callbacks&s

zFuture._invoke_callbackscCs�|j��|jtkr�|jrRd|jjt|�t|j|jjjfSd|jjt|�t|j|jjjfSd|jjt|�t|jfSWdQRXdS)Nz<%s at %#x state=%s raised %s>z <%s at %#x state=%s returned %s>z<%s at %#x state=%s>)	r4r:r
rTr'rr2�_STATE_TO_DESCRIPTION_MAPrS)rrrr�__repr__-s"
			
		
		zFuture.__repr__c
Csg|j�M|jttgkr#dS|jttgkr<dSt|_|jj�WdQRX|j�dS)z�Cancel the future if possible.

        Returns True if the future was cancelled, False otherwise. A future
        cannot be cancelled if it is running or has already completed.
        FTN)r4r:rr
rr	�
notify_allrY)rrrr�cancelAs
	
z
Future.cancelc
Cs(|j�|jttgkSWdQRXdS)z(Return True if the future was cancelled.N)r4r:rr	)rrrrr
Ts
zFuture.cancelledc	Cs"|j�|jtkSWdQRXdS)z1Return True if the future is currently executing.N)r4r:r)rrrrrYs
zFuture.runningcCs+|j�|jtttgkSWdQRXdS)z>Return True of the future was cancelled or finished executing.N)r4r:rr	r
)rrrrrQ^s
zFuture.donecCs |jr|j�n|jSdS)N)rTrS)rrrrZ__get_resultcs	zFuture.__get_resultcCsK|j�1|jtttgkr6|jj|�dSWdQRX||�dS)a%Attaches a callable that will be called when the future finishes.

        Args:
            fn: A callable that will be called with this future as its only
                argument when the future completes or is cancelled. The callable
                will always be called by a thread in the same process in which
                it was added. If the future has already completed or been
                cancelled then the callable will be called immediately. These
                callables are called in the order that they were added.
        N)r4r:rr	r
rUr)r�fnrrr�add_done_callbackis

zFuture.add_done_callbackNc
Cs�|j��|jttgkr+t��n|jtkrD|j�S|jj|�|jttgkrut��n"|jtkr�|j�St��WdQRXdS)aBReturn the result of the call that the future represents.

        Args:
            timeout: The number of seconds to wait for the result if the future
                isn't done. If None, then there is no limit on the wait time.

        Returns:
            The result of the call that the future represents.

        Raises:
            CancelledError: If the future was cancelled.
            TimeoutError: If the future didn't finish executing before the given
                timeout.
            Exception: If the call raised then that exception will be raised.
        N)	r4r:rr	rr
�_Future__get_resultrGr)rrJrrr�resultzs


z
Future.resultc
Cs�|j��|jttgkr+t��n|jtkrA|jS|jj|�|jttgkrrt��n|jtkr�|jSt��WdQRXdS)aUReturn the exception raised by the call that the future represents.

        Args:
            timeout: The number of seconds to wait for the exception if the
                future isn't done. If None, then there is no limit on the wait
                time.

        Returns:
            The exception raised by the call that the future represents or None
            if the call completed without raising.

        Raises:
            CancelledError: If the future was cancelled.
            TimeoutError: If the future didn't finish executing before the given
                timeout.
        N)	r4r:rr	rr
rTrGr)rrJrrrrN�s
zFuture.exceptioncCs�|j��|jtkrGt|_x|jD]}|j|�q,WdS|jtkrct|_dStj	dt
|�|j�td��WdQRXdS)a�Mark the future as running or process any cancel notifications.

        Should only be used by Executor implementations and unit tests.

        If the future has been cancelled (cancel() was called and returned
        True) then any threads waiting on the future completing (though calls
        to as_completed() or wait()) are notified and False is returned.

        If the future was not cancelled then it is put in the running state
        (future calls to running() will return True) and True is returned.

        This method should be called by Executor implementations before
        executing the work associated with this future. If this method returns
        False then the work should not be executed.

        Returns:
            False if the Future was cancelled, True otherwise.

        Raises:
            RuntimeError: if this method was already called or if set_result()
                or set_exception() was called.
        FTz!Future %s in unexpected state: %szFuture in unexpected stateN)r4r:rr	r@r"rrrWZcriticalr2�RuntimeError)rrCrrr�set_running_or_notify_cancel�s
				
z#Future.set_running_or_notify_cancelc
Cs_|j�E||_t|_x|jD]}|j|�q&W|jj�WdQRX|j�dS)z�Sets the return value of work associated with the future.

        Should only be used by Executor implementations and unit tests.
        N)r4rSr
r:r@r r\rY)rrarCrrr�
set_result�s
		zFuture.set_resultc
Cs_|j�E||_t|_x|jD]}|j|�q&W|jj�WdQRX|j�dS)z�Sets the result of the future as being the given exception.

        Should only be used by Executor implementations and unit tests.
        N)r4rTr
r:r@r!r\rY)rrNrCrrr�
set_exception�s
		zFuture.set_exception)rrrrrrYr[r]r
rrQr`r_rarNrcrdrerrrrrRs	"(
rRc@saeZdZdZdd�Zdddddd	�Zd
dd�Zd
d�Zdd�ZdS)�ExecutorzCThis is an abstract base class for concrete asynchronous executors.cOs
t��dS)a Submits a callable to be executed with the given arguments.

        Schedules the callable to be executed as fn(*args, **kwargs) and returns
        a Future instance representing the execution of the callable.

        Returns:
            A Future representing the given call.
        N)�NotImplementedError)rr^r8�kwargsrrr�submits	zExecutor.submitrJN�	chunksizer-cs]�dk	r�tj����fdd�t|�D�����fdd�}|�S)a}Returns an iterator equivalent to map(fn, iter).

        Args:
            fn: A callable that will take as many arguments as there are
                passed iterables.
            timeout: The maximum number of seconds to wait. If None, then there
                is no limit on the wait time.
            chunksize: The size of the chunks the iterable will be broken into
                before being passed to a child process. This argument is only
                used by ProcessPoolExecutor; it is ignored by
                ThreadPoolExecutor.

        Returns:
            An iterator equivalent to: map(func, *iterables) but the calls may
            be evaluated out-of-order.

        Raises:
            TimeoutError: If the entire result iterator could not be generated
                before the given timeout.
            Exception: If fn(*args) raises for any values.
        Ncs"g|]}�j�|��qSr)ri)r;r8)r^rrr�
<listcomp>$s	z Executor.map.<locals>.<listcomp>c3sjzGx@�D]8}�dkr*|j�Vq
|j�tj��Vq
WWdx�D]}|j�qQWXdS)N)rarEr])r)rKrArJrr�result_iterator(s
 
z%Executor.map.<locals>.result_iterator)rE�zip)rr^rJrj�	iterablesrlr)rKr^rArrJr�maps
"
zExecutor.mapTcCsdS)a�Clean-up the resources associated with the Executor.

        It is safe to call this method several times. Otherwise, no other
        methods can be called after this one.

        Args:
            wait: If True then shutdown will not return until all running
                futures have finished executing and the resources used by the
                executor have been reclaimed.
        Nr)rrGrrr�shutdown4szExecutor.shutdowncCs|S)Nr)rrrrr6AszExecutor.__enter__cCs|jdd�dS)NrGTF)rp)r�exc_typeZexc_valZexc_tbrrrr9DszExecutor.__exit__)	rrrrrirorpr6r9rrrrrf�s)
rf)#�
__author__�collectionsZloggingrrErrrrrrrr	r
Z_FUTURE_STATESrZZ	getLoggerrWrVrrr�objectrr#r)r*r/rDrL�
namedtuplerMrGrRrfrrrr�<module>sN	:1�

Zerion Mini Shell 1.0