³ò NÖ±Gc@s×dZddkZyddkZWn ej oeie=‚nXddklZl Z ddk l Z ddklZdddd d d d d dddddddgZeiZeiZeiZeiZ[eZdefd„ƒYZdadad„Z d„Z!eZ"d„Z#defd„ƒYZ$d„Z%defd„ƒYZ&d„Z'd efd!„ƒYZ(d"„Z)d#e(fd$„ƒYZ*d%„Z+d&efd'„ƒYZ,d(a-d)d*„Z.eƒZ/hZ0hZ1defd+„ƒYZ2d,„Z3d-e2fd.„ƒYZ4d/e2fd0„ƒYZ5d1„Z6d2e2fd3„ƒYZ7d4„Z8d5„Z9d6„Z:dd7kl;Z;e5ƒi<Z=ydd8kl>Z?Wn#ej odd9k@l?Z?nXd:„ZAed;jo eAƒndS(<s;Thread module emulating a subset of Java's threading model.iÿÿÿÿN(ttimetsleep(t format_exc(tdequet activeCountt Conditiont currentThreadt enumeratetEventtLocktRLockt SemaphoretBoundedSemaphoretThreadtTimert setprofiletsettracetlocalt stack_sizet_VerbosecBseZdd„Zd„ZRS(cCs$|djo t}n||_dS(N(tNonet_VERBOSEt_Verbose__verbose(tselftverbose((s threading.pyct__init__'s  cGsE|io7||}dtƒiƒ|f}tii|ƒndS(Ns%s: %s (RRtgetNamet_syststderrtwrite(Rtformattargs((s threading.pyct_note,s   N(t__name__t __module__RRR (((s threading.pycR%s cCs |adS(N(t _profile_hook(tfunc((s threading.pycR@scCs |adS(N(t _trace_hook(R$((s threading.pycRDscOs t||ŽS(N(t_RLock(Rtkwargs((s threading.pycR LsR&cBs\eZd d„Zd„Zdd„ZeZd„Zd„Zd„Z d„Z d„Z RS( cCs2ti||ƒtƒ|_d|_d|_dS(Ni(RRt_allocate_lockt _RLock__blockRt _RLock__ownert _RLock__count(RR((s threading.pycRQs  cCs0|i}d|ii|o |iƒ|ifS(Ns <%s(%s, %d)>(R*t __class__R!RR+(Rtowner((s threading.pyct__repr__Ws   icCstƒ}|i|jo+|id|_|id||ƒdSn|ii|ƒ}|o)||_d|_|id||ƒn|id||ƒ|S(Nis!%s.acquire(%s): recursive successs%s.acquire(%s): initial successs%s.acquire(%s): failure(RR*R+R R)tacquire(Rtblockingtmetrc((s threading.pycR/^s   cCs||itƒj otdƒ‚n|id|_}|p*d|_|iiƒ|id|ƒn|id|ƒdS(Nscannot release un-aquired lockis%s.release(): final releases%s.release(): non-final release(R*Rt RuntimeErrorR+RR)treleaseR (Rtcount((s threading.pycR4rs  cCs|iƒdS(N(R4(Rtttvttb((s threading.pyct__exit__scCs?|\}}|iiƒ||_||_|id|ƒdS(Ns%s._acquire_restore()(R)R/R+R*R (Rt.1R5R-((s threading.pyct_acquire_restore„s     cCsK|id|ƒ|i}d|_|i}d|_|iiƒ||fS(Ns%s._release_save()i(R R+R*RR)R4(RR5R-((s threading.pyct _release_save‹s     cCs|itƒjS(N(R*R(R((s threading.pyct _is_owned•sN( R!R"RRR.R/t __enter__R4R9R;R<R=(((s threading.pycR&Os      cOs t||ŽS(N(t _Condition(RR'((s threading.pycR™sR?cBsneZd d d„Zd„Zd„Zd„Zd„Zd„Zd„Z d d„Z dd „Z d „Z RS( c CsÊti||ƒ|djo tƒ}n||_|i|_|i|_y|i|_Wntj onXy|i |_ Wntj onXy|i |_ Wntj onXg|_ dS(N( RRRR t_Condition__lockR/R4R<tAttributeErrorR;R=t_Condition__waiters(RtlockR((s threading.pycRžs&     cCs |iiƒS(N(R@R>(R((s threading.pycR>·scGs|ii|ŒS(N(R@R9(RR((s threading.pycR9ºscCsd|it|iƒfS(Ns(R@tlenRB(R((s threading.pycR.½scCs|iiƒdS(N(R@R4(R((s threading.pycR<ÀscCs|iiƒdS(N(R@R/(Rtx((s threading.pycR;ÃscCs0|iidƒo|iiƒtSntSdS(Ni(R@R/R4tFalsetTrue(R((s threading.pycR=Æs c Csg|iƒptdƒ‚ntƒ}|iƒ|ii|ƒ|iƒ}z|djo|iƒ|id|ƒnØt ƒ|}d}xft o^|idƒ}|oPn|t ƒ}|djoPnt |d|dƒ}t |ƒqW|pA|id||ƒy|ii |ƒWqQtj oqQXn|id||ƒWd|i|ƒXdS( Nscannot wait on un-aquired locks%s.wait(): got itgü©ñÒMb@?iigš™™™™™©?s%s.wait(%s): timed outs%s.wait(%s): got it(R=R3R(R/RBtappendR<RR t_timeRGtmint_sleeptremovet ValueErrorR;(Rttimeouttwaitert saved_statetendtimetdelaytgotitt remaining((s threading.pyctwaitÏs<          icCs¿|iƒptdƒ‚n|i}|| }|p|id|ƒdSn|id|||djodpdƒx?|D]7}|iƒy|i|ƒWq€tj oq€Xq€WdS(Ns cannot notify on un-aquired locks%s.notify(): no waiterss"%s.notify(): notifying %d waiter%sitst(R=R3RBR R4RLRM(RtnRBtwaitersRO((s threading.pyctnotifyùs     cCs|it|iƒƒdS(N(RZRDRB(R((s threading.pyct notifyAll sN( R!R"RRR>R9R.R<R;R=RURZR[(((s threading.pycR?œs      * cOs t||ŽS(N(t _Semaphore(RR'((s threading.pycR sR\cBs;eZddd„Zdd„ZeZd„Zd„ZRS(icCsL|djotdƒ‚nti||ƒttƒƒ|_||_dS(Nis$semaphore initial value must be >= 0(RMRRRR t_Semaphore__condt_Semaphore__value(RtvalueR((s threading.pycRs  cCsšt}|iiƒxs|idjo6|pPn|id|||iƒ|iiƒqW|id|_|id||iƒt}|iiƒ|S(Nis)%s.acquire(%s): blocked waiting, value=%sis%s.acquire: success, value=%s(RFR]R/R^R RURGR4(RR0R2((s threading.pycR/s     cCsQ|iiƒ|id|_|id||iƒ|iiƒ|iiƒdS(Nis%s.release: success, value=%s(R]R/R^R RZR4(R((s threading.pycR42s     cCs|iƒdS(N(R4(RR6R7R8((s threading.pycR9;sN(R!R"RRR/R>R4R9(((s threading.pycR\s   cOs t||ŽS(N(t_BoundedSemaphore(RR'((s threading.pycR ?sR`cBs&eZdZddd„Zd„ZRS(s6Semaphore that checks that # releases is <= # acquiresicCs ti|||ƒ||_dS(N(R\Rt_initial_value(RR_R((s threading.pycRDscCs-|i|ijo td‚nti|ƒS(Ns!Semaphore released too many times(R^RaRMR\R4(R((s threading.pycR4Hs N(R!R"t__doc__RRR4(((s threading.pycR`BscOs t||ŽS(N(t_Event(RR'((s threading.pycRNsRccBs;eZdd„Zd„Zd„Zd„Zdd„ZRS(cCs/ti||ƒttƒƒ|_t|_dS(N(RRRR t _Event__condRFt _Event__flag(RR((s threading.pycRUscCs|iS(N(Re(R((s threading.pyctisSetZscCs<|iiƒzt|_|iiƒWd|iiƒXdS(N(RdR/RGReR[R4(R((s threading.pyctset]s   cCs/|iiƒz t|_Wd|iiƒXdS(N(RdR/RFReR4(R((s threading.pyctcleares  cCsD|iiƒz"|ip|ii|ƒnWd|iiƒXdS(N(RdR/ReRUR4(RRN((s threading.pycRUls   N(R!R"RRRfRgRhRU(((s threading.pycRcQs     is Thread-%dcCstda|tS(Ni(t_counter(ttemplate((s threading.pyct_newnamevs cBs³eZeZeiZddddddd„Zd„Z d„Z d„Z d„Z d„Z d„Zd„Zd„Zdd „Zd „Zd „Zd „Zd „Zd„ZRS(cCs¾|djp td‚ti||ƒ|djo h}n||_t|ptƒƒ|_||_||_ |i ƒ|_ t |_ t |_ttƒƒ|_t|_ti|_dS(Ns#group argument must be None for now(RtAssertionErrorRRt_Thread__targettstrRkt _Thread__namet _Thread__argst_Thread__kwargst _set_daemont_Thread__daemonicRFt_Thread__startedt_Thread__stoppedRR t_Thread__blockRGt_Thread__initializedRRt_Thread__stderr(RtgroupttargettnameRR'R((s threading.pycRŒs        cCs tƒiƒS(N(RtisDaemon(R((s threading.pycRrŸ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)>(RwRlRtRuRsR,R!Ro(Rtstatus((s threading.pycR.£s     cCs‰|iptdƒ‚n|iotdƒ‚n|id|ƒtiƒ|t|(( RwR3RtR t_active_limbo_lockR/t_limboR4t_start_new_threadt_Thread__bootstrapRGRK(R((s threading.pyctstart®s      cCs(|io|i|i|iŽndS(N(RmRpRq(R((s threading.pyctrun¼s cCs>y|iƒWn)|iotdjodSn‚nXdS(N(t_Thread__bootstrap_innerRsRR(R((s threading.pyct __bootstrapÀs cCszÉt|_tiƒ|ttƒ(R¿R¾R·R¹RRK(RR¿tcounter((s threading.pycR†,s  (R!R"RR†(((s threading.pycR¼%s tConsumerThreadcBseZd„Zd„ZRS(cSs)ti|ddƒ||_||_dS(NR{tConsumer(R RR·R5(RR·R5((s threading.pycR7s cSs@x9|idjo(|iiƒ}|GH|id|_qWdS(Nii(R5R·R»(RR¸((s threading.pycR†<s (R!R"RR†(((s threading.pycRÁ5s iiis Producer-%digíµ ÷Æ°>(RR trangeR RHR…RKRŸ( R³R¼RÁtNPtQLtNItQtPtiR6tC((s threading.pyct_tests.      t__main__(BRbtsysRtthreadt ImportErrorRœR!RRIRRKt tracebackRRŒt collectionsRt__all__tstart_new_threadRƒt allocate_lockR(t get_identRŠterrort ThreadErrorRFRtobjectRRR#R%RRR R R&RR?R R\R R`RRcRiRkRR‰R‚R RR¦R«R­R¯RRRRR®t _shutdownR²Rt_threading_localRË(((s threading.pycssr          J s -  $  ú       R