ó V!¶\c@sðddlZddlZddlZddlZddlZddlZdZdZdZdZ dZ dZ dZ d Z d Zd Ze e e eegZid e 6d e 6de 6de6de6ZejdƒZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd „ƒYZd!„Zd"„Ze d#„Z!ej"d$d%ƒZ#e e d&„Z$d'efd(„ƒYZ%d)efd*„ƒYZ&dS(+iÿÿÿÿNs"Brian Quinlan (brian@sweetapp.com)tFIRST_COMPLETEDtFIRST_EXCEPTIONt ALL_COMPLETEDt _AS_COMPLETEDtPENDINGtRUNNINGt CANCELLEDtCANCELLED_AND_NOTIFIEDtFINISHEDtpendingtrunningt cancelledtfinishedsconcurrent.futurestErrorcBseZdZRS(s-Base class for all future-related exceptions.(t__name__t __module__t__doc__(((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyR .stCancelledErrorcBseZdZRS(sThe Future was cancelled.(RRR(((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyR2st TimeoutErrorcBseZdZRS(s*The operation exceeded the given deadline.(RRR(((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyR6st_WaitercBs2eZdZd„Zd„Zd„Zd„ZRS(s;Provides the event that wait() and as_completed() block on.cCstjƒ|_g|_dS(N(t threadingtEventteventtfinished_futures(tself((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyt__init__<scCs|jj|ƒdS(N(Rtappend(Rtfuture((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyt add_result@scCs|jj|ƒdS(N(RR(RR((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyt add_exceptionCscCs|jj|ƒdS(N(RR(RR((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyt add_cancelledFs(RRRRRRR(((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyR:s    t_AsCompletedWaitercBs2eZdZd„Zd„Zd„Zd„ZRS(sUsed by as_completed().cCs&tt|ƒjƒtjƒ|_dS(N(tsuperRRRtLocktlock(R((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRLscCs7|j(tt|ƒj|ƒ|jjƒWdQXdS(N(R"R RRRtset(RR((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRPs cCs7|j(tt|ƒj|ƒ|jjƒWdQXdS(N(R"R RRRR#(RR((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRUs cCs7|j(tt|ƒj|ƒ|jjƒWdQXdS(N(R"R RRRR#(RR((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRZs (RRRRRRR(((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRIs    t_FirstCompletedWaitercBs)eZdZd„Zd„Zd„ZRS(s*Used by wait(return_when=FIRST_COMPLETED).cCs'tt|ƒj|ƒ|jjƒdS(N(R R$RRR#(RR((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRbscCs'tt|ƒj|ƒ|jjƒdS(N(R R$RRR#(RR((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRfscCs'tt|ƒj|ƒ|jjƒdS(N(R R$RRR#(RR((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRjs(RRRRRR(((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyR$_s  t_AllCompletedWaitercBs;eZdZd„Zd„Zd„Zd„Zd„ZRS(s<Used by wait(return_when=FIRST_EXCEPTION and ALL_COMPLETED).cCs8||_||_tjƒ|_tt|ƒjƒdS(N(tnum_pending_callststop_on_exceptionRR!R"R R%R(RR&R'((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRqs  cCs<|j-|jd8_|js2|jjƒnWdQXdS(Ni(R"R&RR#(R((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyt_decrement_pending_callsws  cCs$tt|ƒj|ƒ|jƒdS(N(R R%RR((RR((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyR}scCs=tt|ƒj|ƒ|jr/|jjƒn |jƒdS(N(R R%RR'RR#R((RR((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRs cCs$tt|ƒj|ƒ|jƒdS(N(R R%RR((RR((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRˆs(RRRRR(RRR(((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyR%ns     t_AcquireFuturescBs)eZdZd„Zd„Zd„ZRS(sDA context manager that does an ordered acquire of Future conditions.cCst|dtƒ|_dS(Ntkey(tsortedtidtfutures(RR-((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRscCs%x|jD]}|jjƒq WdS(N(R-t _conditiontacquire(RR((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyt __enter__’scGs%x|jD]}|jjƒq WdS(N(R-R.trelease(RtargsR((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyt__exit__–s(RRRRR0R3(((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyR)Œs  cCs½|tkrtƒ}n€|tkr0tƒ}nhtd„|Dƒƒ}|tkrgt|dtƒ}n1|tkrˆt|dt ƒ}nt d|ƒ‚x|D]}|j j |ƒqŸW|S(Ncss$|]}|jttgkVqdS(N(t_stateRR(t.0tf((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pys ¡sR'sInvalid return condition: %r( RRRR$tsumRR%tTrueRtFalset ValueErrort_waitersR(tfst return_whentwaitert pending_countR6((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyt_create_and_install_waitersšs       ccsgx`|rb|d}x|D]}|j|ƒqW|j|jj|ƒWdQX~|jƒVqWdS(s~ Iterate on the list *fs*, yielding finished futures one by one in reverse order. Before yielding a future, *waiter* is removed from its waiters and the future is removed from each set in the collection of sets *ref_collect*. The aim of this function is to avoid keeping stale references after the future is yielded and before the iterator resumes. iÿÿÿÿN(tremoveR.R;tpop(R<R>t ref_collectR6t futures_set((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyt_yield_finished_futures°s    c csÙ|dk r|tjƒ}nt|ƒ}t|ƒ}t|ƒ4td„|Dƒƒ}||}t|tƒ}WdQXt|ƒ}zx4t||d|fƒD]}|g}|j ƒVq¡WxÝ|rž|dkrÝd}n;|tjƒ}|dkrt dt|ƒ|fƒ‚n|j j |ƒ|j $|j}g|_|j jƒWdQX|jƒx7t||d||fƒD]}|g}|j ƒVq}WqÂWWdx.|D]&}|j|jj|ƒWdQXqªWXdS(snAn 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. css*|] }|jttgkr|VqdS(N(R4RR(R5R6((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pys ßsNRCis%d (of %d) futures unfinished(tNonettimeR#tlenR)R@RtlistRERBRRtwaitR"RtcleartreverseR.R;RA( R<ttimeouttend_timet total_futuresR R R>R6t wait_timeout((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyt as_completedÆsH                  tDoneAndNotDoneFuturess done not_donecCs,t|ƒ¶td„|Dƒƒ}t|ƒ|}|tkrR|rRt||ƒS|tkrŠ|rŠtd„|DƒƒrŠt||ƒSnt|ƒt|ƒkr¯t||ƒSt||ƒ}WdQX|jj |ƒx.|D]&}|j |j j |ƒWdQXqÛW|j |jƒt|t|ƒ|ƒS(sWait 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(R4RR(R5R6((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pys #scss4|]*}|jƒ r|jƒdk r|VqdS(N(R t exceptionRF(R5R6((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pys *sN(R)R#RRRRtanyRHR@RRJR.R;RAtupdateR(R<RMR=tdonetnot_doneR>R6((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRJ s"     tFuturecBs§eZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z dd „Z dd „Zdd „Zd „Zd„Zd„Zd„ZRS(s5Represents the result of an asynchronous computation.cCsItjƒ|_t|_d|_d|_d|_g|_ g|_ dS(s8Initializes the future. Should not be called by clients.N( Rt ConditionR.RR4RFt_resultt _exceptiont _tracebackR;t_done_callbacks(R((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyR>s     cCssxl|jD]a}y||ƒWq tk rAtjd|ƒq tk rT‚q tjd|ƒq Xq WdS(Ns!exception calling callback for %r(R]t ExceptiontLOGGERRSt BaseException(Rtcallback((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyt_invoke_callbacksHs  c Cs³|j¤|jtkr…|jrRd|jjt|ƒt|j|jjjfSd|jjt|ƒt|j|jjjfSnd|jjt|ƒt|jfSWdQXdS(Ns<%s at %#x state=%s raised %s>s <%s at %#x state=%s returned %s>s<%s at %#x state=%s>( R.R4RR[t __class__RR,t_STATE_TO_DESCRIPTION_MAPRZ(R((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyt__repr___s"          cCsf|jM|jttgkr#tS|jttgkr<tSt|_|jjƒWdQX|j ƒtS(s»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. N( R.R4RRR9RRR8t notify_allRb(R((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pytcancelss   cCs'|j|jttgkSWdQXdS(s(Return True if the future was cancelled.N(R.R4RR(R((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyR †s cCs!|j|jtkSWdQXdS(s1Return True if the future is currently executing.N(R.R4R(R((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyR ‹s cCs*|j|jtttgkSWdQXdS(s>Return True of the future was cancelled or finished executing.N(R.R4RRR(R((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRVs cCs\|jrQt|jtjƒr-|jj}nt|jƒ}||j|j‚n|jSdS(N(R[t isinstancettypest InstanceTypeRcttypeR\RZ(Rtexception_type((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyt __get_result•s  cCsJ|j1|jtttgkr6|jj|ƒdSWdQX||ƒdS(s%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(R.R4RRRR]R(Rtfn((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pytadd_done_callback¢s  cCs¡|j’|jttgkr+tƒ‚n|jtkrD|jƒS|jj|ƒ|jttgkrutƒ‚n"|jtkrŽ|jƒStƒ‚WdQXdS(sBReturn 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( R.R4RRRRt_Future__get_resultRJR(RRM((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pytresult³s     cCs­|jž|jttgkr+tƒ‚n|jtkrJ|j|jfS|jj|ƒ|jttgkr{tƒ‚n(|jtkrš|j|jfSt ƒ‚WdQXdS(sqReturn a tuple of (exception, traceback) 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( R.R4RRRRR[R\RJR(RRM((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pytexception_infoÒs   cCs|j|ƒdS(sUReturn 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. i(Rr(RRM((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRSóscCs•|j†|jtkrGt|_x|jD]}|j|ƒq,WtS|jtkrct|_t St j dt |ƒ|jƒt dƒ‚WdQXdS(s¸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. s!Future %s in unexpected state: %ssFuture in unexpected stateN(R.R4RRR;RR9RRR8R_tcriticalR,t RuntimeError(RR>((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pytset_running_or_notify_cancels      cCs^|jE||_t|_x|jD]}|j|ƒq&W|jjƒWdQX|jƒdS(s‹Sets the return value of work associated with the future. Should only be used by Executor implementations and unit tests. N(R.RZRR4R;RRfRb(RRqR>((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyt set_result/s   cCsg|jN||_||_t|_x|jD]}|j|ƒq/W|jjƒWdQX|jƒdS(s£Sets the result of the future as being the given exception and traceback. Should only be used by Executor implementations and unit tests. N( R.R[R\RR4R;RRfRb(RRSt tracebackR>((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pytset_exception_info<s    cCs|j|dƒdS(sSets the result of the future as being the given exception. Should only be used by Executor implementations and unit tests. N(RxRF(RRS((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyt set_exceptionKsN(RRRRRbReRgR R RVRpRoRFRqRrRSRuRvRxRy(((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRX;s"         !  ( tExecutorcBs>eZdZd„Zd„Zed„Zd„Zd„ZRS(sCThis is an abstract base class for concrete asynchronous executors.cOs tƒ‚dS(s 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(tNotImplementedError(RRnR2tkwargs((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pytsubmitUs csx|jdƒ‰ˆdk r.ˆtjƒ‰ngtj|ŒD]}|j||Œ^q>‰‡‡‡fd†}|ƒS(s~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. 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. RMc3s|zYˆjƒxHˆrWˆdkr6ˆjƒjƒVqˆjƒjˆtjƒƒVqWWdxˆD]}|jƒqcWXdS(N(RLRFRBRqRGRg(R(RNR<RM(s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pytresult_iteratorzs   & N(tgetRFRGt itertoolstizipR}(RRnt iterablesR|R2R~((RNR<RMs;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pytmap`s  . cCsdS(s‹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. N((RRJ((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pytshutdown‰s cCs|S(N((R((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyR0–scCs|jdtƒtS(NRJ(R„R8R9(Rtexc_typetexc_valtexc_tb((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyR3™s( RRRR}RƒR8R„R0R3(((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pyRzRs  ) ('t collectionstloggingRR€RGRit __author__RRRRRRRRRt_FUTURE_STATESRdt getLoggerR_R^R RRtobjectRRR$R%R)R@RERFRQt namedtupleRRRJRXRz(((s;/tmp/pip-install-usGedi/futures/concurrent/futures/_base.pytsX           B 1ÿ