mò õÔ5;c@s²dZdklZdkZdkZdkZdkZdd d„Zeƒ\ZZ dei fd„ƒYZ e Z dfd „ƒYZ e Zd „Zed jo eƒndS( s FileLock - Implements a file lock mechanism that does not depend on fcntl. Copyright (c) 1997-2000, Marc-Andre Lemburg; mailto:mal@lemburg.com See the documentation for further information on copyrights, or contact the author. All Rights Reserved. (s ExitFunctionsNt localhosts 127.0.0.1cCs•y dk}Wntj o |SnXyC|djo|iƒ}n|i|ƒ}|i|ƒd}Wn|i j o |Sn X||fSdS(sÿ Returns fully qualified (hostname, ip) for the given hostname. If hostname is not given, the default name of the local host is chosen. Defaults to default in case an error occurs while trying to determine the data. Ni( tsockett ImportErrortdefaultthostnametNonet gethostnamet gethostbynametipt gethostbyaddrterror(RRRR((t;/data/zmath/lib/python2.4/site-packages/mx/Misc/FileLock.pyt _fqhostnames     tErrorcBstZRS(N(t__name__t __module__(((R R ,stSymbolicFileLockc Bs‰tZdZdZd„Zd„Zddeieeie i e e d„Z de ieeie i d„Ze id„Zd „ZRS( sÚ Implements a file lock mechanism that uses symbolic links for locking. Note that since the mechanism does not use file system function calls this may not always work in the desired way. The lock is acquired per process, not per thread. Instancevariables: filename - file the lock applies to lockfilename - name of the lock file locked - indicator if the lock is in position (1) or not (0) icCs3||_|d|_d|_ti|iƒdS(Ns.lockedi(tfilenametselft lockfilenametlockedt ExitFunctionstregistertunlock(RR((R t__init__Hs   cCs=|io|idƒnyti|iƒWnnXdS(Ni(RRRRt deregister(R((R t__del__Ps  iôf0.0001c Csä|iodSn|i}d|tiƒf} |ƒ|d} ti i } ti } ti}xt| |ƒp,y| | |ƒWn|j oqœXPn||ƒ|ƒ| joy"ti||ƒdƒ\} }Wn+|j o}|d|i|f‚nXti|ƒ}| |jo&t| dd ƒd}||j}nd}|o]yti|d ƒWq²|j o6}yti|iƒWqc|j oq®Xqcq²Xn|d |i| ||f‚qcqcWd|_dS( s= Try to lock the file for this process, waiting timeout ms if necessary. Raises an exception if a timeout occurs. Multiple locking by the same process is not an error. Note that a non existent path to the file will also result in a timeout. If the lock is held by a process running on our host, a timeout will first invoke a check of the locking process. If it is not alive anymore, the lock is removed and granted to the current process. Ns%s:%if0.001it:s!file "%s" could not be locked: %sRs???is$file "%s" is locked by process %s:%i(s???s???( RRRRtostgetpidtlockinfottimettimeouttstoptpathtislinktsymlinktmakelinktreadlinkR tsleept sleeptimetstringtsplitthostt locking_pidR twhyRtatoiR tother_ipRtsamehosttkilltunlink(RR R(R'R RR RRRR%R#R!R+R&R-R0R/R,R((R tlockYsN       "  %cCsk|ipdSnd|_y||iƒWn#|j o|d|i‚nX|o||ƒndS(s Release the lock, letting other processes using this mechanism access the file. Multiple unlocking is not an error. Raises an exception if the lock file was already deleted by another process. After having unlocked the file the process sleeps for sleeptime seconds to give other processes a chance to acquire the lock too. If the lock will only be used every once in a while by the process, it is safe to set it to 0. Nislock file "%s" is already gonei(RRR2RR R R(R'(RR(R2R R'R ((R R¢s  cCs(d|_y||iƒWnnXdS(s/ Remove any existing lock on the file. iN(RRR2R(RR2((R t remove_lock¿s  cCs d|ii|it|ƒfS(Ns<%s for "%s" at %x>(Rt __class__RRtid(R((R t__repr__Ës(RRt__doc__RRRRR'R RR RRR3R2RR4R7(((R R4s   *I! cCsUtdƒ}xAtdƒD]3}d|G|iƒti|dƒ|iƒqWHdS(Ns test.locki's%i f100000.0(RR3trangetiRR'R(R:R3((R t_testÔs   t__main__(Rs 127.0.0.1(R8RRt exceptionsRR)RR RRt StandardErrorR t FileLockErrorRtFileLockR;R( R@R)R RR;RRR RRR=R?R((R t? s $ž