;ò ò0;c@sïdZdkZdkZdkZdkZdkZedjdeifd„ƒYZdei fd„ƒYZ dfd„ƒYZ d fd „ƒYZ d fd „ƒYZ hZd „Zd„Zd„Zd„Zdeifd„ƒYZdS(s This module uses the threading and Queue modules to create a pool of reusable threads. After creating an instance of ThreadPool, one queues functions to be excecuted. The pool dispatches the functions to the waiting threads, which call them. When queueing a function on the pool with *pool*.put(), an instance of ReturnValue is returned. ReturnValue is a subclass of lazy.Lazy, and can be used in any context that a regular lazy expression can. When evaluating a ReturnValue, the evaluating thread will block until the other thread has completed its work and loaded the return value of the function into the ReturnValue instance. VLocks are an alternative to RLocks which include a visible queue threads waiting for the lock. lock, unlock, getLockFor, and deleteLockFor work with a module-level dictionary of objects to locks, and can be more convenient than working with lock objects directly. Locked and Async are callable wrappers around a function. Async calls return immediately after queueing their function on a thread pool, while Locked calls first acquire the lock they were passed on creation, call their function, and release the lock. Ns1.0.1sWorkercBsGtZdZeeedd„Zd„Zd„Zd„Zd„ZRS(sL A Thread which works for a ThreadPool, getting work from that queue, executing, and then returning to the queue again to wait for more work. The work that it does is to call a no-args function. Using functional.py it is possible to make this include any number of callbacks, arbitrary error reporting, etc. icCsVtii|d|d|ƒ||_d|_d|_ t |_ ||_ ||_dS(Nsgroupsnamei(s threadingsThreads__init__sselfsgroupsnames getJobFuncs_getJobs_busys_errorsNones_jobs trap_errorss _ignore_errorsexitFuncs _exitFunc(sselfs getJobFuncsgroupsnamesexitFuncs trap_errors((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys__init__>s     cCs |iSdS(N(sselfs_busy(sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysisBusyHscCs |iSdS(N(sselfs_job(sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysgetJobKscCs|idSdS(Ni(sselfs_job(sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysgetAssociatedValueNscCsþxßno×d|_|iƒ}d|_||_|d o/|dtj o|ditƒndSniy|dƒ}d}Wn!t j o}|}d}nX|dtj o|di|d|ƒnt|_q W|i o|i ƒndS(Niis asException( sselfs_busys_getJobsjobs_jobsNonesloadsvals asExceptions StandardErrorses _exitFunc(sselfsesvals asExceptionsjob((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysrunQs*         ( s__name__s __module__s__doc__sNones__init__sisBusysgetJobsgetAssociatedValuesrun(((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysWorker6s    s ReturnValuecBs5tZdZd„Zd„Zdd„Zd„ZRS(s® A lazy return value. Calls to eval block until the value is loaded, but the ReturnValue instance can be stored or passed to other functions in the meantime. cCsdS(N((sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys__init__vscCsx|iidƒ o>tiƒ|id<|iiƒ|iiƒ|iiƒn|ido |i ‚n|i SdS(Ns_values _conditions _asException( sselfs__dict__shas_keys threadings Conditions _conditionsacquireswaitsreleases_value(sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysevalys   icCs\||id<||id<|iidƒo+|iiƒ|iiƒ|iiƒndS(Ns _asExceptions_values _condition( s asExceptionsselfs__dict__svalshas_keys _conditionsacquires notifyAllsrelease(sselfsvals asException((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysload„s     cCs"dttt|ƒƒƒdSdS(Ns(sstrshexsidsself(sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys__repr__Œs(s__name__s __module__s__doc__s__init__sevalsloads__repr__(((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys ReturnValueps   sAsynccBs tZdZd„Zd„ZRS(s Wrapped around a normal method or function, this will cause calls to the function to return ReturnValue tokens immediately, while the function runs in a different thread. Example: >>> p = ThreadPool() >>> threading.currentThread() <_MainThread(MainThread, started)> >>> def pr(): ... print threading.currentThread() ... >>> pr() <_MainThread(MainThread, started)> >>> f = Async(pr, p) >>> f() >>> cCs||_||_dS(N(sfuncsselfs_funcspools_pool(sselfsfuncspool((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys__init__¤s cOs|ii|iƒSdS(N(sselfs_poolsputs_func(sselfsargsskwargs((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys__call__¨s(s__name__s __module__s__doc__s__init__s__call__(((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysAsync‘s  sLockedcBs tZdZd„Zd„ZRS(sÑ Wrapped around a normal method or function, this will cause calls to the function to block if another thread has the lock. Note that this shortcut only protects things that use the same lock. cCs||_||_dS(N(sfuncsselfs_funcslocks_lock(sselfsfuncslock((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys__init__²s cOs9|iiƒzt|i||ƒWd|iiƒXdS(N(sselfs_locksacquiresapplys_funcsargsskwargssrelease(sselfsargsskwargs((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys__call__µs  (s__name__s __module__s__doc__s__init__s__call__(((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysLocked¬s  sVLockcBsPtZdZd„Zd„Zd„Zd„Zdd„Zd„Zd„Z RS( sM Similar to an RLock, but with a (V)isible queue of waiting threads. cCs.tiƒ|_t|_g|_d|_dS(Ni(s threadingsLocksselfslocksNonesownersqueues ownerlocks(sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys__init__Às  cCs|itj SdS(N(sselfsownersNone(sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysisLockedÆscCs |iSdS(N(sselfsowner(sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysgetOwnerÉscCs |iSdS(N(sselfsqueue(sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys getWaitingÌsicCsYtiƒ}|ii|ƒ|ii|ƒ|ii |ƒ|i d|_ ||_ dS(Ni( s threadings currentThreadsthreadsselfsqueuesappendslocksacquiresblockingsremoves ownerlockssowner(sselfsblockingsthread((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysacquireÏs  cCsctiƒ|ijpt‚|id|_|idjot|_|iiƒdSndSdS(Nii( s threadings currentThreadsselfsownersAssertionErrors ownerlockssNoneslocksrelease(sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysrelease×s  cCs*dt|iƒdt|iƒdSdS(Ns(sstrsselfsownersqueue(sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys__str__ás( s__name__s __module__s__doc__s__init__sisLockedsgetOwners getWaitingsacquiresreleases__str__(((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysVLock¼s       cCs4ti|ƒ otƒt|'s(sfiltersselfs_pool(sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysgetBusyThreads&scCstd„|iƒSdS(NcCs |iƒ S(N(sxsisBusy(sx((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys*s(sfiltersselfs_pool(sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysgetIdleThreads)scCstd„|iƒSdS(NcCs |iƒS(N(sxsisAlive(sx((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys-s(sfiltersselfs_pool(sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysgetLiveThreads,scCsjt|id|idt|iƒƒ}|id|_|ii|ƒ|i |i ƒƒ|i ƒdS(Nsnames - i( sWorkersselfsgets_namesstrs_threadCountersws_poolsappends setDaemonsisDaemonsstart(sselfsw((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys _addThread/s )cCs=d|_x-|iD]"}tii|tttfƒqWdS(s¾ Cause this pool to shut down gracefully, by refusing to create new threads, and scheduling None (treated as a command to end) jobs for all its live threads. iN(sselfs_deads_poolsthreadsQueuesputsNone(sselfsthread((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysshutDown6s   cCs<|i o|iƒnx|iƒotdƒqWdS(Nid(sselfs_deadsshutDownsgetLiveThreadsssleep(sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysrestartAs   cCs¤|io td‚n|iƒ|_x(t|iƒ|ijo|iƒq)WxLt|iƒƒ|i ƒjo,t|iƒ|i jo|iƒqTPqTWdS(s¦ Ensure that the correct number of (live) threads are available for doing work. It is not normally necessary for clients to call this method. sThis pool has been shut down.N( sselfs_deads RuntimeErrorsgetLiveThreadss_poolslens _minThreadss _addThreadsgetIdleThreadssqsizes _maxThreads(sself((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys checkThreadsGs  cCs:|iƒtƒ}tii||||f|ƒ|SdS(N( sselfs checkThreadss ReturnValuesrvsQueuesputsitems associatedsblock(sselfsitemsblocks associatedsrv((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pysputWs  (s__name__s __module__s__doc__s__init__sisDaemons getThreadssgetBusyThreadssgetIdleThreadssgetLiveThreadss _addThreadsshutDownsrestarts checkThreadssNonesput(((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys ThreadPool s         (s__doc__s threadingstimessysslazysQueues __version__sThreadsWorkersLazyExprs ReturnValuesAsyncsLockedsVLocks_lockss getLockFors deleteLockForslocksunlocks ThreadPool(sQueueslazysLockedslocksVLocks ThreadPoolsWorkerssyss threadingsunlocks ReturnValuestimes getLockForsAsyncs deleteLockFors_locks((s=/mnt/gmirror/ports/devel/py-xoltar-toolkit/work/threadpool.pys?-s"      :!)