Ñò ›ˆQc @s¼dZddkZddkZddkZddkZddkZddkZeidƒZde fd„ƒYZ de fd„ƒYZ dei fd „ƒYZd e fd „ƒYZdS( sHA simple thread pool class for doing multiple concurrent API operations.iÿÿÿÿNs gcutil-logstThreadPoolErrorcBseZdZRS(s!An error occurred in this module.(t__name__t __module__t__doc__(((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pyRst OperationcBs;eZdZd„Zd„Zd„Zd„Zd„ZRS(sbAn operation to be executed by the threadpool. Override this and implement the Run() method. cCsd|_t|_dS(s Initializer.N(tNonet_resulttFalset_raised_exception(tself((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pyt__init__(s cCstdƒ‚dS(s/Override this method to execute this operation.spure virtual method calledN(tNotImplementedError(R ((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pytRun-scCs‹y|iƒ|_Wnqt|_tiƒ}t|ƒdjp|ddjo|d|_n|d|_ti t i ƒƒnXdS(s%Internal runner that captures result.iiiN( R RtTrueRtsystexc_infotlenRtLOGGERtdebugt tracebackt format_exc(R ta((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pyt _DoOperation1s  $ cCs|iS(síGet the operation's result. If the operation is incomplete the return value will be None. If the operation raised an exception, the return value will be the exception object. Returns: The operation's result. (R(R ((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pytResultAs cCs|iS(s«Did the operation raise an exception? Will be False if the operation has not yet completed. Returns: True if an exception was raised by the operation. (R(R ((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pytRaisedExceptionMs(RRRR R RRR(((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pyR"s     tWorkercBs eZdZd„Zd„ZRS(s0Thread executing tasks from a given tasks queue.cCs0tii|ƒ||_t|_|iƒdS(N(t threadingtThreadR t_queueR tdaemontstart(R tqueue((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pyR [s  cCsXxQtoI|iiƒ}|djo|iiƒPn|iƒ|iiƒqWdS(N(R RtgetRt task_doneR(R top((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pytrunas   (RRRR R#(((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pyRXs t ThreadPoolcBs\eZdZdZdZdZdZd„Zd„Zd„Z d„Z d „Z d „Z RS( s«Pool of threads consuming tasks from a queue. Note that operations on the thread pool itself (submitting, waiting, shutdown) are not, themselves, multithread safe. iiiicCsmtiƒ|_||_|i|_g|_x-t|ƒD]}|iit|iƒƒq:W|i |_dS(N( tQueueRt _num_threadst _NOT_RUNNINGt_statet_workerstrangetappendRt_RUNNING(R t num_threadst_((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pyR ys    cCs%|i|ijo|iƒndS(N(R(R,t WaitShutdown(R ((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pyt__del__ƒscCsW|i|ijotdƒ‚nt|tƒptdƒ‚n|ii|ƒdS(sAdd an operation to the queue. Note that this is not thread safe. Args: op: An Operation object to add to the thread pool queue Raises: ThreadPoolError: if not in running state. ValueError: if op isn't an Operation object sThreadPool not runnings%Nonoperation argument to AddOperationN(R(R,Rt isinstanceRt ValueErrorRtput(R R"((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pytAddˆs cCs)x"|iiƒptidƒqWdS(s´Wait for all items to clear. This will come up for air once in a while so that we can capture keyboard interrupt. Unfortunately Queue.join() isn't interruptable. gš™™™™™É?N(Rtemptyttimetsleep(R ((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pyt _InternalWaitšscCs1|i|ijotdƒ‚n|iƒdS(sœWait for completion of all the tasks in the queue. Note that this is not thread safe. Raises: ThreadPoolError: if not in running state. sThreadPool not runningN(R(R,RR8(R ((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pytWaitAll¤scCss|i|ijotdƒ‚n|i|_x't|iƒD]}|iidƒq?W|i ƒ|i |_dS(skWait for completion of all tasks and shut down the ThreadPool. Note that this is not thread safe. sThreadPool not runningN( R(R,Rt _TERMINATINGR*R&RR3RR8t _TERMINATED(R R.((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pyR/°s  ( RRRR'R,R:R;R R0R4R8R9R/(((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pyR$ls   (RtloggingR%RRR6Rt getLoggerRt ExceptionRtobjectRRRR$(((s`/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.pyts      6