mò %U²Ic@sËdZdkZy dkZWn ej oeie=‚nXdklZl Z dk l Z dklZddddd d d d d dddddgZeiZeiZeiZeiZ[eZeodefd„ƒYZndefd„ƒYZdada d„Z!d„Z"eZ#d„Z$defd„ƒYZ%d„Z&defd„ƒYZ'd„Z(defd „ƒYZ)d!„Z*d"e)fd#„ƒYZ+d$„Z,d%efd&„ƒYZ-d'a.d(d)„Z/eƒZ0hZ1hZ2defd*„ƒYZ3d+„Z4d,e3fd-„ƒYZ5d.e3fd/„ƒYZ6d0„Z7d1e3fd2„ƒYZ8d3„Z9d4„Z:d5„Z;e6ƒyd6kl<Z=Wn ej od7k>l=Z=nXd8„Z?ed9jo e?ƒndS(:s;Thread module emulating a subset of Java's threading model.N(stimessleep(s format_exc(sdequet activeCountt Conditiont currentThreadt enumeratetEventtLocktRLockt SemaphoretBoundedSemaphoretThreadtTimert setprofiletsettracetlocalt_VerbosecBstZdd„Zd„ZRS(NcCs$|djo t}n||_dS(N(tverbosetNonet_VERBOSEtselft_Verbose__verbose(RR((t&/data/zmath/lib/python2.4/threading.pyt__init__'s  cGsE|io7||}dtƒiƒ|f}tii|ƒndS(Ns%s: %s ( RRtformattargsRtgetNamet_syststderrtwrite(RRR((Rt_note,s  (t__name__t __module__RRR(((RR%s cBstZdd„Zd„ZRS(NcCsdS(N((RR((RR6scGsdS(N((RR((RR8s(RRRRR(((RR5s cCs |adS(N(tfunct _profile_hook(R((RR @scCs |adS(N(Rt _trace_hook(R((RR DscOs t||ŽS(N(t_RLockRtkwargs(RR#((RRLsR"cBsMtZdd„Zd„Zdd„Zd„Zd„Zd„Zd„Z RS( NcCs2ti||ƒtƒ|_d|_d|_dS(Ni( RRRRt_allocate_lockt _RLock__blockRt _RLock__ownert _RLock__count(RR((RRQs  cCs-d|ii|io |iiƒ|ifS(Ns <%s(%s, %d)>(Rt __class__RR&RR'(R((Rt__repr__WsicCs¾tƒ}|i|jo6|id|_to|id||ƒndSn|ii |ƒ}|o4||_d|_to|id||ƒqºnto|id||ƒn|S(Nis!%s.acquire(%s): recursive successs%s.acquire(%s): initial successs%s.acquire(%s): failure( RtmeRR&R't __debug__RtblockingR%tacquiretrc(RR,R*R.((RR-]s   cCs’tƒ}|i|jp td‚|id|_}|p5d|_|ii ƒt o|i d|ƒqŽnt o|i d|ƒndS(Nsrelease() of un-acquire()d lockis%s.release(): final releases%s.release(): non-final release( RR*RR&tAssertionErrorR'tcountRR%treleaseR+R(RR*R0((RR1os   cCsJ|\}}|iiƒ||_||_to|id|ƒndS(Ns%s._acquire_restore()( R0townerRR%R-R'R&R+R(Rt.2R0R2((Rt_acquire_restore~s    cCsVto|id|ƒn|i}d|_|i}d|_|ii ƒ||fS(Ns%s._release_save()i( R+RRR'R0R&R2RR%R1(RR0R2((Rt _release_save…s     cCs|itƒjS(N(RR&R(R((Rt _is_owneds( RRRRR)R-R1R4R5R6(((RR"Os      cOs t||ŽS(N(t _ConditionRR#(RR#((RR“sR7cBs\tZddd„Zd„Zd„Zd„Zd„Zdd„Zdd„Z d „Z RS( NcCsÊti||ƒ|djo tƒ}n||_|i|_|i |_ y|i |_ Wnt j onXy|i |_ Wnt j onXy|i |_ Wnt j onXg|_dS(N(RRRRtlockRRt_Condition__lockR-R1R5tAttributeErrorR4R6t_Condition__waiters(RR8R((RR˜s&     cCsd|it|iƒfS(Ns(RR9tlenR;(R((RR)±scCs|iiƒdS(N(RR9R1(R((RR5´scCs|iiƒdS(N(RR9R-(Rtx((RR4·scCs0|iidƒo|iiƒtSntSdS(Ni(RR9R-R1tFalsetTrue(R((RR6ºs cCs‚|iƒp td‚tƒ}|iƒ|ii|ƒ|iƒ}z'|djo)|iƒt o|i d|ƒqlnîtƒ|}d}xfto^|idƒ}|oPn|tƒ}|djoPnt|d|dƒ}t|ƒq•W|pLt o|i d||ƒny|ii|ƒWqltj oqlXnt o|i d||ƒnWd|i|ƒXdS( Nswait() of un-acquire()d locks%s.wait(): got itf0.00050000000000000001iif0.050000000000000003s%s.wait(%s): timed outs%s.wait(%s): got it(RR6R/R$twaiterR-R;tappendR5t saved_statettimeoutRR+Rt_timetendtimetdelayR?tgotitt remainingtmint_sleeptremovet ValueErrorR4(RRCRFRGR@RBRERH((RtwaitÃsB         icCsÄ|iƒp td‚|i}|| }|p#to|id|ƒndSn|id|||djodpdƒx?|D]7}|i ƒy|i |ƒWq…t j oq…Xq…WdS(Nsnotify() of un-acquire()d locks%s.notify(): no waiterss"%s.notify(): notifying %d waiter%sitst( RR6R/R;tntwaitersR+RR@R1RKRL(RRPR@R;RQ((Rtnotifyìs    cCs|it|iƒƒdS(N(RRRR<R;(R((Rt notifyAllýs( RRRRR)R5R4R6RMRRRS(((RR7–s    ) cOs t||ŽS(N(t _SemaphoreRR#(RR#((RRsRTcBs,tZddd„Zdd„Zd„ZRS(NicCsF|djp td‚ti||ƒttƒƒ|_||_ dS(Nis$Semaphore initial value must be >= 0( tvalueR/RRRRRRt_Semaphore__condt_Semaphore__value(RRUR((RRscCs°t}|iiƒx‰|idjoA|pPnto|id|||iƒn|ii ƒqW|id|_to|id||iƒnt }|ii ƒ|S(Nis)%s.acquire(%s): blocked waiting, value=%sis%s.acquire: success, value=%s( R>R.RRVR-RWR,R+RRMR?R1(RR,R.((RR-s"    cCs\|iiƒ|id|_to|id||iƒn|iiƒ|iiƒdS(Nis%s.release: success, value=%s(RRVR-RWR+RRRR1(R((RR1!s   (RRRRR-R1(((RRTs cOs t||ŽS(N(t_BoundedSemaphoreRR#(RR#((RR+sRXcBs&tZdZded„Zd„ZRS(s6Semaphore that checks that # releases is <= # acquiresicCs ti|||ƒ||_dS(N(RTRRRURt_initial_value(RRUR((RR0scCs-|i|ijo td‚nti|ƒS(Ns!Semaphore released too many times(RRWRYRLRTR1(R((RR14s (RRt__doc__RRR1(((RRX.s cOs t||ŽS(N(t_EventRR#(RR#((RR:sR[cBs;tZdd„Zd„Zd„Zd„Zdd„ZRS(NcCs/ti||ƒttƒƒ|_t|_dS(N( RRRRRRt _Event__condR>t _Event__flag(RR((RRAscCs|iS(N(RR](R((RtisSetFscCs<|iiƒzt|_|iiƒWd|iiƒXdS(N(RR\R-R?R]RSR1(R((RtsetIs   cCs/|iiƒz t|_Wd|iiƒXdS(N(RR\R-R>R]R1(R((RtclearQs   cCsD|iiƒz"|ip|ii|ƒnWd|iiƒXdS(N(RR\R-R]RMRCR1(RRC((RRMXs   (RRRRR^R_R`RM(((RR[=s     is Thread-%dcCstda|tS(Ni(t_counterttemplate(Rb((Rt_newnamebs cBsªtZeZeiZdddfhdd„Zd„Z d„Z d„Z d„Z d„Z d„Zd„Zdd „Zd „Zd „Zd „Zd „Zd„ZRS(NcCs§|djp td‚ti||ƒ||_t |pt ƒƒ|_ ||_||_|iƒ|_t|_t|_ttƒƒ|_t|_ti|_dS(Ns#group argument must be None for now(tgroupRR/RRRRttargett_Thread__targettstrtnameRct _Thread__nameRt _Thread__argsR#t_Thread__kwargst _set_daemont_Thread__daemonicR>t_Thread__startedt_Thread__stoppedRRt_Thread__blockR?t_Thread__initializedRRt_Thread__stderr(RRdReRhRR#R((RRxs      cCs tƒiƒS(N(RtisDaemon(R((RRl‰scCst|ip td‚d}|io d}n|io d}n|io|d}nd|ii|i |fS(Ns Thread.__init__() was not calledtinitialtstartedtstoppeds daemons <%s(%s, %s)>( RRqR/tstatusRnRoRmR(RRi(RRw((RR)s     cCs‰|ip td‚|i p td‚to|id|ƒntiƒ|t|x|ip|ii ƒq‹Wto|id|ƒqJn…t ƒ|}xt|ipN|t ƒ}|djo to|id|ƒnPn|ii |ƒqÖWto|id|ƒnWd|iiƒXdS(NsThread.__init__() not calleds'cannot join thread before it is startedscannot join current threads%%s.join(): waiting until thread stopss%s.join(): thread stoppedis%s.join(): timed out(RRqR/RnRR+RoRRpR-RCRRMRDtdeadlineRFR1(RRCRFR”((Rtjoins6        cCs|ip td‚|iS(NsThread.__init__() not called(RRqR/Ri(R((RR.scCs'|ip td‚t|ƒ|_dS(NsThread.__init__() not called(RRqR/RgRhRi(RRh((RtsetName2scCs&|ip td‚|io|i S(NsThread.__init__() not called(RRqR/RnRo(R((RtisAlive6scCs|ip td‚|iS(NsThread.__init__() not called(RRqR/Rm(R((RRs:scCs6|ip td‚|i p td‚||_dS(NsThread.__init__() not calleds)cannot set daemon status of active thread(RRqR/RntdaemonicRm(RR˜((Rt setDaemon>s(RRR>RqRtexc_infoR‚RRRlR)R|R}R{RŒRR•RR–R—RsR™(((RR os     A  "     cOs t||ŽS(N(t_TimerRR#(RR#((RR EsR›cBs/tZdZghd„Zd„Zd„ZRS(s²Call a function after a specified number of seconds: t = Timer(30.0, f, args=[], kwargs={}) t.start() t.cancel() # stop the timer's action if it's still waiting cCsAti|ƒ||_||_||_||_tƒ|_dS(N( R RRtintervaltfunctionRR#Rtfinished(RRœRRR#((RRPs      cCs|iiƒdS(s(Stop the timer if it hasn't finished yetN(RRžR_(R((RtcancelXscCsN|ii|iƒ|iiƒp|i|i|iŽn|iiƒdS(N( RRžRMRœR^RRR#R_(R((RR}\s(RRRZRRŸR}(((RR›Hs  t _MainThreadcBs#tZd„Zd„Zd„ZRS(NcCsZti|ddƒt|_tiƒ|ttƒ(R((RRlpscCs„|iƒtƒ}|oto|id|ƒq9nx|o|iƒtƒ}q<Wto|id|ƒn|iƒdS(Ns%s: waiting for other threadss %s: exiting(RRŒt_pickSomeNonDaemonThreadttR+RR•R(RR¦((Rt __exitfuncss   (RRRRlR¤(((RR es cCs;x4tƒD])}|iƒ o|iƒo|Sq q WdS(N(RR¦RsR—R(R¦((RR¥€s   t _DummyThreadcBs&tZd„Zd„Zdd„ZRS(NcCsGti|dtdƒƒt|_tiƒ|tt ƒR/(RRC((RR•šs(RRRRlRR•(((RR¨Žs  cCs0yttƒSWntj otƒSnXdS(N(R~RR‘R¨(((RR scCs.tiƒttƒttƒ}tiƒ|S(N(RxR-R<R~RyR0R1(R0((RR§s  cCs.tiƒtiƒtiƒ}tiƒ|S(N(RxR-R~tvaluesRytactiveR1(Rª((RR­s  (s_local(slocalc Csdtfd„ƒY}dtfd„ƒY}dtfd„ƒY}d} d} d }|| ƒ}g}xEt | ƒD]7}|||ƒ}|i d |d ƒ|i|ƒqsW|||| ƒ}x"|D]}|iƒtd ƒqÈW|iƒx|D]}|iƒq÷W|iƒdS( Nt BoundedQueuecBs#tZd„Zd„Zd„ZRS(NcCsVti|ƒtƒ|_t|iƒ|_t|iƒ|_||_t ƒ|_ dS(N( RRRRtmonRR.twctlimittdequetqueue(RR®((RRÆs    cCs•|iiƒx;t|iƒ|ijo!|id|ƒ|ii ƒqW|ii |ƒ|id|t|iƒƒ|i i ƒ|ii ƒdS(Nsput(%s): queue fulls put(%s): appended, length now %d(RR¬R-R<R°R®RtitemR­RMRAR.RRR1(RR±((RtputÎs   cCs‚|iiƒx)|ip|idƒ|iiƒqW|iiƒ}|id|t |iƒƒ|i i ƒ|ii ƒ|S(Nsget(): queue emptysget(): got %s, %d left( RR¬R-R°RR.RMtpopleftR±R<R­RRR1(RR±((RtgetÙs     (RRRR²R´(((RR«Äs  tProducerThreadcBstZd„Zd„ZRS(NcCs)ti|ddƒ||_||_dS(NRhtProducer(R RRR°tquota(RR°R·((RRæs cCsjdkl}d}xP||ijo?|d}|iid|iƒ|fƒt|ƒdƒqWdS(N(srandomiis%s.%df1.0000000000000001e-05(trandomtcounterRR·R°R²RRJ(RR¸R¹((RR}ës   (RRRR}(((RRµäs tConsumerThreadcBstZd„Zd„ZRS(NcCs)ti|ddƒ||_||_dS(NRhtConsumer(R RRR°R0(RR°R0((RRös cCs@x9|idjo(|iiƒ}|GH|id|_qWdS(Nii(RR0R°R´R±(RR±((RR}ûs (RRRR}(((RRºôs iiis Producer-%dif9.9999999999999995e-07(RR«R RµRºtNPtQLtNItQtPtrangetiR¦R–RAtCR|RJR•( R¾RÃRµRÂR«RÀRºR¿R¦R¼R½((Rt_testÂs.      t__main__(@RZtsysRtthreadt ImportErrorR’RttimeRDtsleepRJt tracebackt format_excRt collectionsR¯t__all__tstart_new_threadRzt allocate_lockR$t get_identRterrort ThreadErrorR>RR+tobjectRRR R!R R RRR"RR7RRTRRXRR[RaRcRxR~RyR R R›R R¥R¨RRRt_localR t_threading_localRÄ()RXRRRRRJRÓRzRRÎR[R›R"RÄR RxRRR¯R R¨R R7RR RRR RTRcRÇR¥RyRR~R RRDR$RR((Rt?sp     0        D k '  $  Ö      R