Ñò PhEc@s|ddddgZddkZddkZddkZddkZddkZddkTyddkZddk Z Wn+e j oddk Zddk Z nXyeiƒeZWn9yddkZeZWqòe j o eZqòXnXddd„ƒYZeƒZdeded„Zd dd „ƒYZd efd „ƒYZd efd„ƒYZdefd„ƒYZdS(t SynchronizertNameLockt _threadingt_threadiÿÿÿÿN(t*cBsWeZdZeƒZddd„ƒYZded„Ze d„Z d„Z d„Z RS( sßa proxy for an RLock object that is stored in a name based registry. Multiple threads can get a reference to the same RLock based on the name alone, and synchronize operations related to that name. t NLContainercBs eZdZd„Zd„ZRS(scant put Lock as a weakrefcCs-|otiƒ|_ntiƒ|_dS(N(RtRLocktlocktLock(tselft reentrant((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyt__init__.scCs|iS(N(R(R ((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyt__call__3s(t__name__t __module__t__doc__R R (((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR,s cCs|i||ƒ|_dS(N(t _get_lockR(R t identifierR ((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR 6scCs|iƒi|ƒS(N(Rtacquire(R twait((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR9scCs|iƒiƒdS(N(Rtrelease(R ((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR<scs7|djotiˆƒStii|‡fd†ƒS(Ncs tiˆƒS((RR((R (s:/usr/lib/python2.6/site-packages/myghty/synchronization.pytDs(tNoneRRtlockstget(R RR ((R s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR?s (N( R RRtWeakValuedRegistryRRRtFalseR tTrueRRR(((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR"s    csitp t}n|o0tidˆtiƒf‡‡‡fd†ƒStidˆ‡fd†ƒSdS(sY returns an object that synchronizes a block against many simultaneous read operations and several synchronized write operations. Write operations are assumed to be much less frequent than read operations, and receive precedence when they request a write lock. uses strategies to determine if locking is performed via threading objects or file objects. the identifier identifies a name this Synchronizer is synchronizing against. All synchronizers of the same identifier will lock against each other, within the effective thread/process scope. use_files determines if this synchronizer will lock against thread mutexes or file locks. this sets the effective scope of the synchronizer, i.e. it will lock against other synchronizers in the same process, or against other synchronizers referencing the same filesystem referenced by lock_dir. the acquire/relase methods support nested/reentrant operation within a single thread via a recursion counter, so that only the outermost call to acquire/release has any effect. s file_%s_%scstˆˆˆƒS((tFileSynchronizer((tdigest_filenamesRtlock_dir(s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyRjss condition_%scs tˆƒS((tConditionSynchronizer((R(s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyRmsN(t has_flockRt synchronizerstsync_getRt get_ident(Rt use_filesRR((RRRs:/usr/lib/python2.6/site-packages/myghty/synchronization.pyRKs  0t SyncStatecBseZdZd„ZRS(s\used to track the current thread's reading/writing state as well as reentrant block countingcCsd|_t|_t|_dS(Ni(treentrantcountRtwritingtreading(R ((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR ss  (R RRR (((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR%pstSynchronizerImplcBseeZdZd„Zd„Zed„Zd„Zed„Zd„Z d„Z d„Z d „Z RS( sºbase for the synchronizer implementations. the acquire/release methods keep track of re-entrant calls within the current thread, and delegate to the do_XXX methods when appropriate.cOsdS(N((R targstparams((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR |scCsk|i}|io d‚n|ip d‚n|idjo|iƒt|_n|id8_dS(Nslock is in writing stateslock is not in reading statei(tstateR'R(R&tdo_release_read_lockR(R R,((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pytrelease_read_locks     cCs|i}|io d‚n|idjo>|i|ƒ}|p|o|id7_t|_n|S|io|id7_tSdS(Nslock is in writing stateii(R,R'R&tdo_acquire_read_lockRR((R RR,tx((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pytacquire_read_lock‹s    cCsk|i}|io d‚n|ip d‚n|idjo|iƒt|_n|id8_dS(Nslock is in reading stateslock is not in writing statei(R,R(R'R&tdo_release_write_lockR(R R,((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pytrelease_write_lockšs     cCs|i}|io d‚n|idjo>|i|ƒ}|p|o|id7_t|_n|S|io|id7_tSdS(Nslock is in reading stateii(R,R(R&tdo_acquire_write_lockRR'(R RR,R0((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pytacquire_write_lock¦s    cCs tƒ‚dS(N(tNotImplementedError(((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR-µscCs tƒ‚dS(N(R6(((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR/¶scCs tƒ‚dS(N(R6(((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR2·scCs tƒ‚dS(N(R6(((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR4¸s( R RRR R.RR1R3R5R-R/R2R4(((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR)xs      RcBsVeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z RS( s÷a synchronizer using lock files. as it relies upon flock(), which is not safe to use with the same file descriptor among multiple threads (one file descriptor per thread is OK), a separate FileSynchronizer must exist in each thread.cCsutƒ|_|djotiƒ}n|}t||gddd|ƒ|_|ii|_t |_ d|_ dS(Nt extensions.locktdigest( R%R,Rttempfilet gettempdirt EncodedPathtencpathtpathtfilenameRtopenedtfiledesc(R RRR((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR Às  ! cCst|ipfyti|i|ƒ|_Wn:tj o.}|iiƒti|i|ƒ|_nXt|_ndS(N( R?tostopenR>R@tOSErrorR<tverify_directoryR(R tmodete((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyt_openÎs  cCs„|ititiBƒ|pHy'ti|ititiBƒt }Wnt j o t }nX|Sti|itiƒt SdS(N( RGRAtO_CREATtO_RDONLYtfcntltflockR@tLOCK_SHtLOCK_NBRtIOErrorR(R Rtret((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR/×s  cCs„|ititiBƒ|pHy'ti|ititiBƒt }Wnt j o t }nX|Sti|itiƒt SdS(N( RGRARHtO_WRONLYRJRKR@tLOCK_EXRMRRNR(R RRO((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR4çs  cCs|iƒdS(N(trelease_all_locks(R ((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR-öscCs|iƒdS(N(RR(R ((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR2ùscCsA|io3ti|itiƒti|iƒt|_ndS(N(R?RJRKR@tLOCK_UNRAtcloseR(R ((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyRRüs cCsKti|itiƒo.yti|iƒWqGtj oqGXndS(N(RAtaccessR>tF_OKtremoveRC(R ((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyt__del__s ( R RRR RGR/R4R-R2RRRX(((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyRºs      RcBsPeZdZd„Zed„ƒZed„Zd„Zed„Z d„Z RS(s‰a synchronizer using a Condition. this synchronizer is based on threading.Lock() objects and therefore must be shared among threads.cCsCtdd„ƒ|_d|_d|_titiƒƒ|_dS(NtcreatorcSstƒS((R%(((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyRsi( t ThreadLocalt tlocalstatetasyncRtcurrent_sync_operationRt ConditionRt condition(R R((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR s  cCs |iƒS((R[(R ((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyRscCs‹|iiƒ|o)xH|idj o|iiƒqWn#|idj o|iiƒtS|id7_|iiƒ|ptSdS(Ni( R_RR]RRRRR\R(R R((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR/s   cCs||iiƒ|id8_|idjo%|idj o|iiƒqkn|idjo d‚n|iiƒdS(Niis7Synchronizer error - too many release_read_locks called(R_RR\R]Rt notifyAllR(R ((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR-1s  cCsÑ|iiƒ|o)xH|idj o|iiƒqWn#|idj o|iiƒtStiƒ|_|i djo6|o|iiƒq´d|_|iiƒtSn|iiƒ|pt SdS(Ni( R_RR]RRRRRt currentThreadR\R(R R((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR4Cs$     cCsT|iiƒ|itiƒjo d‚nd|_|iiƒ|iiƒdS(Ns>Synchronizer error - current thread doesnt have the write lock(R_RR]RRaRR`R(R ((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR2hs     ( R RRR tpropertyR,RR/R-R4R2(((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyR s    %(((t__all__RAtweakrefR9tretsyst myghty.utiltthreadRt threadingRt ImportErrort dummy_threadtdummy_threadingtgetwindowsversionRR RJRRRR!RRR%tobjectR)RR(((s:/usr/lib/python2.6/site-packages/myghty/synchronization.pyt s0<       & %BQ