ϪfdZddlmZddlZddlmZmZddlmZddl m Z ddl m Z ddl mZdd lmZed Zed Z dd Zd ZdZdZdZgdZy)zY Extended thread dispatching support. For basic support see reactor threading API docs. ) annotationsN)CallableTypeVar) ParamSpec)defer)IReactorFromThreads)failure) ThreadPool_P_Rcntjdfd }|j||g|i|S)a3 Call the function C{f} using a thread from the given threadpool and return the result as a Deferred. This function is only used by client code which is maintaining its own threadpool. To run a function in the reactor's threadpool, use C{deferToThread}. @param reactor: The reactor in whose main thread the Deferred will be invoked. @param threadpool: An object which supports the C{callInThreadWithCallback} method of C{twisted.python.threadpool.ThreadPool}. @param f: The function to call. @param args: positional arguments to pass to f. @param kwargs: keyword arguments to pass to f. @return: A Deferred which fires a callback with the result of f, or an errback with a L{twisted.python.failure.Failure} if f throws an exception. c||rjj|yjj|yN)callFromThreadcallbackerrback)successresultdreactors :/usr/lib/python3/dist-packages/twisted/internet/threads.pyonResultz#deferToThreadPool..onResult9s.   " "1::v 6  " "199f 5)rboolrz_R | BaseExceptionreturnNone)rDeferredcallInThreadWithCallback)r threadpoolfargskwargsrrs` @rdeferToThreadPoolr#s9:"NN,A6 (J''!EdEfE HrcLddlm}t||j|g|i|S)at Run a function in a thread and return the result as a Deferred. @param f: The function to call. @param args: positional arguments to pass to f. @param kwargs: keyword arguments to pass to f. @return: A Deferred which fires a callback with the result of f, or an errback with a L{twisted.python.failure.Failure} if f throws an exception. rr)twisted.internetrr# getThreadPool)r r!r"rs r deferToThreadr(Ds)) Wg&;&;&=q R4 R6 RRrc*|D]\}}}||i|y)z" Run a list of functions. N) tupleListr r!r"s r _runMultipler,Us&%4 46rc<ddlm}|jt|y)z Run a list of functions in the same thread. tupleList should be a list of (function, argsList, kwargsDict) tuples. rr%N)r&r callInThreadr,)r+rs rcallMultipleInThreadr/]s ) y1rctjfd}|j|j}t|tj r|j |S)a Run a function in the reactor from a thread, and wait for the result synchronously. If the function returns a L{Deferred}, wait for its result and return that. @param reactor: The L{IReactorThreads} provider which will be used to schedule the function call. @param f: the callable to run in the reactor thread @type f: any callable. @param a: the arguments to pass to C{f}. @param kw: the keyword arguments to pass to C{f}. @return: the result of the L{Deferred} returned by C{f}, or the result of C{f} if it returns anything other than a L{Deferred}. @raise Exception: If C{f} raises a synchronous exception, C{blockingCallFromThread} will raise that exception. If C{f} returns a L{Deferred} which fires with a L{Failure}, C{blockingCallFromThread} will raise that failure's exception (see L{Failure.raiseException}). cntjgi}|jjyr)r maybeDeferredaddBothput)rar kwqueues r_callFromThreadz/blockingCallFromThread.._callFromThreads-$$Q11b1uyy!r)Queuerget isinstancer FailureraiseException)rr r5r6r8rr7s ``` @rblockingCallFromThreadr>hsO, KKME" ?+ YY[F&'//* Mr)r(r#r/r>) rrrr r zCallable[_P, _R]r!z_P.argsr"z _P.kwargsrzdefer.Deferred[_R])__doc__ __future__rr7r9typingrrrr&rtwisted.internet.interfacesrtwisted.pythonr twisted.python.threadpoolr r r r#r(r,r/r>__all__r*rrrFs #$";"0t_ T]' ' ' '   '  '  ' TS"2 F r