Viewing File: /opt/alt/python35/lib/python3.5/site-packages/lockfile/__pycache__/pidlockfile.cpython-35.opt-1.pyc



UV@sdZddlmZddlZddlZddlZddlmZmZm	Z	m
Z
mZmZGdddeZ
dd	Zd
dZdd
ZdS)z8 Lockfile behaviour implemented via Unix PID files.
    )absolute_importN)LockBase
AlreadyLocked
LockFailed	NotLocked	NotMyLockLockTimeoutc@sseZdZdZddddZddZdd	Zd
dZddd
ZddZ	ddZ
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')
    FNcCs&tj||d||j|_dS)NF)r__init__pathZunique_name)selfrZthreadedtimeoutr/pidlockfile.pyr$szPIDLockFile.__init__cCs
t|jS)z- Get the PID from the lock file.
            )read_pid_from_pidfiler)r
rrrread_pid*szPIDLockFile.read_pidcCstjj|jS)zv Test if the lock is currently held.

            The lock is held if the PID file for this lock exists.

            )osrexists)r
rrr	is_locked/szPIDLockFile.is_lockedcCs"|jo!tj|jkS)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.
        )rrgetpidr)r
rrri_am_locking7szPIDLockFile.i_am_lockingcCs/|dk	r|n|j}tj}|dk	rI|dkrI||7}xyt|jWntk
r"}z|jtjkrtj|kr|dk	r|dkrtd|jntd|jtj	|dk	r|dpdnt
d|jWYdd}~XqLXdSqLWdS)z Acquire the lock.

        Creates the PID file for this lock, or raises an error if
        the lock could not be acquired.
        Nrz&Timeout waiting to acquire lock for %sz%s is already locked
g?zfailed to create %s)rtimewrite_pid_to_pidfilerOSErrorerrnoEEXISTr	rsleepr)r
rend_timeexcrrracquire?s$

&&zPIDLockFile.acquirecCsO|jstd|j|js>td|jt|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)rrrrrremove_existing_pidfile)r
rrrrelease_s
zPIDLockFile.releasecCst|jdS)z Break an existing lock.

            Removes the PID file if it already exists, otherwise does
            nothing.

            N)r"r)r
rrr
break_locklszPIDLockFile.break_lock)__name__
__module____qualname____doc__rrrrr!r#r$rrrrr
s	 
r
cCssd}yt|d}Wntk
r-YnBX|jj}yt|}Wntk
rdYnX|j|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)openIOErrorreadlinestripint
ValueErrorclose)pidfile_pathpidpidfilelinerrrrvs


rcCsotjtjBtjB}d}tj|||}tj|d}tj}|jd||jdS)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_WRONLYr*fdopenrwriter0)r1Z
open_flagsZ	open_modeZ
pidfile_fdr3r2rrrrs	rcCsUytj|Wn=tk
rP}z|jtjkr;nWYdd}~XnXdS)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)rremoverrENOENT)r1r rrrr"sr")r(Z
__future__rrrrrrrrrr	r
rrr"rrrr<module>
s.]"
Back to Directory File Manager