Pc@s dZddlZyddlZWnek rBeje=nXddlZddlmZ m Z ddl m ZddlmZdddd d d d d dddddddddgZejZejZejZejZ[ejddeddddeZdefdYZe a!e a"dZ#d Z$eZ%d!Z&d"efd#YZ'd$Z(d%efd&YZ)d'Z*d(efd)YZ+d*Z,d+e+fd,YZ-d-Z.d.efd/YZ/d0a0d1d2Z1ea2iZ3iZ4defd3YZ5d4Z6d5e5fd6YZ7d7e5fd8YZ8d9Z9d:e5fd;YZ:d<Z;e;Z<d=Z=e=Z>d>Z?d?Z@dd@lmAZAe8jBZCyddAlmDZEWn!ek rddBlFmEZEnXdCZGdDZHedEkreHndS(Fs;Thread module emulating a subset of Java's threading model.iN(ttimetsleep(t format_exc(tdequet activeCountt active_countt Conditiont currentThreadtcurrent_threadt enumeratetEventtLocktRLockt SemaphoretBoundedSemaphoretThreadtTimert setprofiletsettracetlocalt stack_sizetignoretcategorytmodulet threadingtmessages sys.exc_cleart_VerbosecBseZddZdZRS(cCs"|dkrt}n||_dS(N(tNonet_VERBOSEt_Verbose__verbose(tselftverbose((s..\python\lib\threading.pyt__init__:s  cGs@|jr<||}dtj|f}tjj|ndS(Ns%s: %s (RRtnamet_syststderrtwrite(Rtformattargs((s..\python\lib\threading.pyt_note?s   N(t__name__t __module__RR R'(((s..\python\lib\threading.pyR8s cCs |adS(N(t _profile_hook(tfunc((s..\python\lib\threading.pyRSscCs |adS(N(t _trace_hook(R+((s..\python\lib\threading.pyRWscOs t||S(N(t_RLock(R&tkwargs((s..\python\lib\threading.pyR _sR-cBs\eZd dZdZddZeZdZdZdZ dZ dZ RS( cCs2tj||t|_d|_d|_dS(Ni(RR t_allocate_lockt _RLock__blockRt _RLock__ownert _RLock__count(RR((s..\python\lib\threading.pyR ds  cCsH|j}yt|j}Wntk r-nXd|jj||jfS(Ns<%s owner=%r count=%d>(R1t_activeR!tKeyErrort __class__R(R2(Rtowner((s..\python\lib\threading.pyt__repr__js  icCst}|j|kr?|jd|_|jd||dS|jj|}|r||_d|_|jd||n|jd|||S(Nis!%s.acquire(%s): recursive successs%s.acquire(%s): initial successs%s.acquire(%s): failure(t _get_identR1R2R'R0tacquire(Rtblockingtmetrc((s..\python\lib\threading.pyR9ss   cCsx|jtkr!tdn|jd|_}|sdd|_|jj|jd|n|jd|dS(Nscannot release un-acquired lockis%s.release(): final releases%s.release(): non-final release(R1R8t RuntimeErrorR2RR0treleaseR'(Rtcount((s..\python\lib\threading.pyR>s  cCs|jdS(N(R>(Rtttvttb((s..\python\lib\threading.pyt__exit__scCs?|\}}|jj||_||_|jd|dS(Ns%s._acquire_restore()(R0R9R2R1R'(Rt count_ownerR?R6((s..\python\lib\threading.pyt_acquire_restores     cCsK|jd||j}d|_|j}d|_|jj||fS(Ns%s._release_save()i(R'R2R1RR0R>(RR?R6((s..\python\lib\threading.pyt _release_saves     cCs|jtkS(N(R1R8(R((s..\python\lib\threading.pyt _is_ownedsN( R(R)RR R7R9t __enter__R>RCRERFRG(((s..\python\lib\threading.pyR-bs     cOs t||S(N(t _Condition(R&R.((s..\python\lib\threading.pyRsRIcBsteZd d dZdZdZdZdZdZdZ d dZ dd Z d Z e Z RS( cCstj|||dkr(t}n||_|j|_|j|_y|j|_Wntk rlnXy|j |_ Wntk rnXy|j |_ Wntk rnXg|_ dS(N( RR RR t_Condition__lockR9R>RFtAttributeErrorRERGt_Condition__waiters(RtlockR((s..\python\lib\threading.pyR s&        cCs |jjS(N(RJRH(R((s..\python\lib\threading.pyRHscGs|jj|S(N(RJRC(RR&((s..\python\lib\threading.pyRCscCsd|jt|jfS(Ns(RJtlenRL(R((s..\python\lib\threading.pyR7scCs|jjdS(N(RJR>(R((s..\python\lib\threading.pyRFscCs|jjdS(N(RJR9(Rtx((s..\python\lib\threading.pyREscCs+|jjdr#|jjtStSdS(Ni(RJR9R>tFalsetTrue(R((s..\python\lib\threading.pyRGs cCsY|jstdnt}|j|jj||j}z|dkrv|j|jd|nt |}d}x`t r|jd}|rPn|t }|dkrPnt |d|d}t |qW|s0|jd||y|jj |WqCtk r,qCXn|jd||Wd|j|XdS( Nscannot wait on un-acquired locks%s.wait(): got itgMb@?iig?s%s.wait(%s): timed outs%s.wait(%s): got it(RGR=R/R9RLtappendRFRR't_timeRQtmint_sleeptremovet ValueErrorRE(Rttimeouttwaitert saved_statetendtimetdelaytgotitt remaining((s..\python\lib\threading.pytwaits:           icCs|jstdn|j}|| }|sH|jd|dS|jd|||dkridpldx=|D]5}|jy|j|Wqwtk rqwXqwWdS(Ns!cannot notify on un-acquired locks%s.notify(): no waiterss"%s.notify(): notifying %d waiter%sitst(RGR=RLR'R>RVRW(RtnRLtwaitersRY((s..\python\lib\threading.pytnotifys      cCs|jt|jdS(N(RdRNRL(R((s..\python\lib\threading.pyt notifyAll!sN(R(R)RR RHRCR7RFRERGR_RdRet notify_all(((s..\python\lib\threading.pyRIs      *  cOs t||S(N(t _Semaphore(R&R.((s..\python\lib\threading.pyR 'sRgcBs;eZdddZddZeZdZdZRS(icCsJ|dkrtdntj||tt|_||_dS(Nis$semaphore initial value must be >= 0(RWRR RR t_Semaphore__condt_Semaphore__value(RtvalueR((s..\python\lib\threading.pyR .s  cCst}|jjxo|jdkrX|s/Pn|jd|||j|jjqW|jd|_|jd||jt}|jj|S(Nis)%s.acquire(%s): blocked waiting, value=%sis%s.acquire: success, value=%s(RPRhR9RiR'R_RQR>(RR:R<((s..\python\lib\threading.pyR95s     cCsQ|jj|jd|_|jd||j|jj|jjdS(Nis%s.release: success, value=%s(RhR9RiR'RdR>(R((s..\python\lib\threading.pyR>Js     cCs|jdS(N(R>(RR@RARB((s..\python\lib\threading.pyRCSsN(R(R)RR R9RHR>RC(((s..\python\lib\threading.pyRg*s   cOs t||S(N(t_BoundedSemaphore(R&R.((s..\python\lib\threading.pyRWsRkcBs&eZdZdddZdZRS(s6Semaphore that checks that # releases is <= # acquiresicCs tj|||||_dS(N(RgR t_initial_value(RRjR((s..\python\lib\threading.pyR \scCs+|j|jkrtdntj|S(Ns!Semaphore released too many times(RiRlRWRgR>(R((s..\python\lib\threading.pyR>`s N(R(R)t__doc__RR R>(((s..\python\lib\threading.pyRkZscOs t||S(N(t_Event(R&R.((s..\python\lib\threading.pyR fsRncBsAeZddZdZeZdZdZddZRS(cCs/tj||tt|_t|_dS(N(RR RR t _Event__condRPt _Event__flag(RR((s..\python\lib\threading.pyR mscCs|jS(N(Rp(R((s..\python\lib\threading.pytisSetrscCs<|jjzt|_|jjWd|jjXdS(N(RoR9RQRpRfR>(R((s..\python\lib\threading.pytsetws   cCs/|jjz t|_Wd|jjXdS(N(RoR9RPRpR>(R((s..\python\lib\threading.pytclears  cCsI|jjz'|js,|jj|n|jSWd|jjXdS(N(RoR9RpR_R>(RRX((s..\python\lib\threading.pyR_s    N( R(R)RR Rqtis_setRrRsR_(((s..\python\lib\threading.pyRnis     is Thread-%dcCstda|tS(Ni(t_counter(ttemplate((s..\python\lib\threading.pyt_newnames cBseZeZejZejZdddddddZ dZ dZ dZ dZdZdZdZdZd Zdd Zed Zejd Zed ZdZeZedZejdZdZdZdZdZRS(cCs|dkstdtj|||dkr=i}n||_t|pUt|_||_||_ |j |_ d|_ t |_t|_tt|_t|_tj|_dS(Ns#group argument must be None for now(RtAssertionErrorRR t_Thread__targettstrRwt _Thread__namet _Thread__argst_Thread__kwargst _set_daemont_Thread__daemonict_Thread__identR t_Thread__startedRPt_Thread__stoppedRR t_Thread__blockRQt_Thread__initializedR"R#t_Thread__stderr(RtgroupttargetR!R&R.R((s..\python\lib\threading.pyR s         cCs tjS(N(Rtdaemon(R((s..\python\lib\threading.pyR~scCs|jstdd}|jjr3d}n|jrEd}n|jr[|d7}n|jdk r~|d|j7}nd|jj |j |fS(Ns Thread.__init__() was not calledtinitialtstartedtstoppeds daemons %ss <%s(%s, %s)>( RRxRRtRRRRR5R(R{(Rtstatus((s..\python\lib\threading.pyR7s     cCs|jstdn|jjr6tdn|jd|t|t|(R((s..\python\lib\threading.pyt__stopJs   cCsHyttt=WdQXWn&tk rCdtjkrDqDnXdS(sARemove current thread from the dict of currently running threads.Ntdummy_threading(RR3R8R4R"tmodules(R((s..\python\lib\threading.pyt__deletePs  cCs<|jstdn|jjs6tdn|tkrTtdn|jsp|jd|n|jjz|dkrx|js|jj qW|jd|njt |}xZ|js|t }|dkr|jd|Pn|jj |qW|jd|Wd|jj 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( RR=RRtRRR'RR9RR_RSR>(RRXtdeadlineR\((s..\python\lib\threading.pytjoinss.         cCs|jstd|jS(NsThread.__init__() not called(RRxR{(R((s..\python\lib\threading.pyR!scCs(|jstdt||_dS(NsThread.__init__() not called(RRxRzR{(RR!((s..\python\lib\threading.pyR!scCs|jstd|jS(NsThread.__init__() not called(RRxR(R((s..\python\lib\threading.pytidentscCs,|jstd|jjo+|j S(NsThread.__init__() not called(RRxRRtR(R((s..\python\lib\threading.pytisAlivescCs|jstd|jS(NsThread.__init__() not called(RRxR(R((s..\python\lib\threading.pyRscCsC|jstdn|jjr6tdn||_dS(NsThread.__init__() not calleds)cannot set daemon status of active thread(RR=RRtR(Rtdaemonic((s..\python\lib\threading.pyRs  cCs|jS(N(R(R((s..\python\lib\threading.pytisDaemonscCs ||_dS(N(R(RR((s..\python\lib\threading.pyt setDaemonscCs|jS(N(R!(R((s..\python\lib\threading.pytgetNamescCs ||_dS(N(R!(RR!((s..\python\lib\threading.pytsetNamesN(( R(R)RPRR"texc_infoRt exc_clearRRR R~R7RRRRRRt_Thread__deleteRtpropertyR!tsetterRRtis_aliveRRRRR(((s..\python\lib\threading.pyRs4        J  # !    cOs t||S(N(t_Timer(R&R.((s..\python\lib\threading.pyRsRcBs/eZdZgidZdZdZRS(sCall 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 cCsAtj|||_||_||_||_t|_dS(N(RR tintervaltfunctionR&R.R tfinished(RRRR&R.((s..\python\lib\threading.pyR s      cCs|jjdS(s(Stop the timer if it hasn't finished yetN(RRr(R((s..\python\lib\threading.pytcancelscCsL|jj|j|jjs;|j|j|jn|jjdS(N(RR_RRtRR&R.Rr(R((s..\python\lib\threading.pyRs(R(R)RmR RR(((s..\python\lib\threading.pyRs t _MainThreadcBs#eZdZdZdZRS(cCsHtj|dd|jj|jt|tt(Rtitem((s..\python\lib\threading.pytput|s   cSs|jjx'|js6|jd|jjqW|jj}|jd|t|j|jj |jj |S(Nsget(): queue emptysget(): got %s, %d left( RR9RR'R<R_tpopleftRNRRdR>(RR((s..\python\lib\threading.pytgets     (R(R)R RR(((s..\python\lib\threading.pyRrs  tProducerThreadcBseZdZdZRS(cSs)tj|dd||_||_dS(NR!tProducer(RR Rtquota(RRR((s..\python\lib\threading.pyR s cSshddlm}d}xK||jkrc|d}|jjd|j|ft|dqWdS(Ni(trandomiis%s.%dgh㈵>(RRRRR!RU(RRtcounter((s..\python\lib\threading.pyRs  (R(R)R R(((s..\python\lib\threading.pyRs tConsumerThreadcBseZdZdZRS(cSs)tj|dd||_||_dS(NR!tConsumer(RR RR?(RRR?((s..\python\lib\threading.pyR s cSs>x7|jdkr9|jj}|GH|jd|_qWdS(Nii(R?RR(RR((s..\python\lib\threading.pyRs(R(R)R R(((s..\python\lib\threading.pyRs iiis Producer-%digư>(RRtrangeR!RRRRUR( RRRtNPtQLtNItQtPtiR@tC((s..\python\lib\threading.pyt_testps(       t__main__(IRmtsysR"Rt ImportErrorRR(twarningsRRSRRUt tracebackRRt collectionsRt__all__tstart_new_threadRt allocate_lockR/t get_identR8terrort ThreadErrortfilterwarningstDeprecationWarningRPRtobjectRRR*R,RRR R R-RRIR RgRRkR RnRuRwRR3RRRRRRRRRRRRR RRt _shutdownRRt_threading_localRR(((s..\python\lib\threading.pyts              M u -  '  '         $ R