/՘n|dZddlmZddlZddlZddlZddlmZmZm Z m Z m Z m Z GddeZ dZd Zd ZdS) z8 Lockfile behaviour implemented via Unix PID files. )absolute_importN)LockBase AlreadyLocked LockFailed NotLocked NotMyLock LockTimeoutc@eZdZdZd dZdZdZdZd dZd Z d Z dS) PIDLockFileaA Lockfile implemented as a Unix PID file. The lock file is a normal file named by the attribute `path`. A lock's PID file contains a single line of text, containing the process ID (PID) of the process that acquired the lock. >>> lock = PIDLockFile('somefile') >>> lock = PIDLockFile('somefile') FNcLtj||d||j|_dS)NF)r__init__path unique_name)selfrthreadedtimeouts /srv/buildsys-work-dir/castor/build_node/builder-1/MVYGK/unpkd_srcs/imunify360-venv-2.6.0/opt/imunify360/venv/lib/python3.11/site-packages/lockfile/pidlockfile.pyrzPIDLockFile.__init__$s+ $eW5559c*t|jS)z- Get the PID from the lock file. )read_pid_from_pidfilerrs rread_pidzPIDLockFile.read_pid*s%TY///rcJtj|jS)zv Test if the lock is currently held. The lock is held if the PID file for this lock exists. )osrexistsrs r is_lockedzPIDLockFile.is_locked/s w~~di(((rc||o(tj|kS)z Test if the lock is held by the current process. Returns ``True`` if the current process ID matches the number stored in the PID file. )rrgetpidrrs r i_am_lockingzPIDLockFile.i_am_locking7s, ~~BBIKK4==??$BBrc||n|j}tj}| |dkr||z } t|jdS#t$r}|jt jkrktj|kr6||dkrtd|jztd|jztj |dur|dz pdntd|jzYd}~nd}~wwxYw) z Acquire the lock. Creates the PID file for this lock, or raises an error if the lock could not be acquired. NrTz&Timeout waiting to acquire lock for %sz%s is already locked g?zfailed to create %s) rtimewrite_pid_to_pidfilerOSErrorerrnoEEXISTr rsleepr)rrend_timeexcs racquirezPIDLockFile.acquire?s@%0''dl9;;  7Q;;  H  $TY///  H H H9 ,,y{{X--".7Q;;"-/=.2i/8#9#99#00F04 1:#;#;;Jwd2Cw|JsKKKK$%:TY%FGGGLKKKK H sA C/BC**C/c|std|jz|st d|jzt |jdS)z Release the lock. Removes the PID file to release the lock, or raises an error if the current process does not hold the lock. z%s is not lockedz%s is locked, but not by meN)rrrr r remove_existing_pidfilers rreleasezPIDLockFile.release_sm~~ <.:;; ;  "" G9DIEFF F *****rc.t|jdS)z Break an existing lock. Removes the PID file if it already exists, otherwise does nothing. N)r-rrs r break_lockzPIDLockFile.break_lockls  *****r)FN)N) __name__ __module__ __qualname____doc__rrrr r+r.r0rrr r s%%%% 000 )))CCC@ + + ++++++rr cd} t|d}|} t|}n#t$rYnwxYw|n#t $rYnwxYw|S)z Read the PID recorded in the named PID file. Read and return the numeric PID recorded as text in the named PID file. If the PID file cannot be read, or if the content is not a valid PID, return ``None``. Nr)openreadlinestripint ValueErrorcloseIOError) pidfile_pathpidpidfilelines rrrvs C|S))!!'')) d))CC    D  %      ( Js"A0A AA0 A=<A=c*tjtjztjz}d}tj|||}tj|d}tj}|d|z|dS)u Write the PID in the named PID file. Get the numeric process ID (“PID”) of the current process and write it to the named file as a line of text. iwz%s N) rO_CREATO_EXCLO_WRONLYr8fdopenrwriter=)r? open_flags open_mode pidfile_fdrAr@s rr$r$sv*ry(2;6JIz9==Ji C((G )++C MM&3, MMOOOOOrc tj|dS#t$r"}|jtjkrnYd}~dSd}~wwxYw)z Remove the named PID file if it exists. Removing a PID file that doesn't already exist puts us in the desired state, so we ignore the condition if the file does not exist. N)rremover%r&ENOENT)r?r*s rr-r-s` ,  9 $ $   DDDDDs A?A)r4 __future__rr&rr#rrrrr r r rr$r-r5rrrRs'&&&&& Z+Z+Z+Z+Z+(Z+Z+Z+zD0r