Viewing File: /opt/alt/python38/lib/python3.8/site-packages/lockfile/__pycache__/pidlockfile.cpython-38.opt-1.pyc
U
UV @ st d Z ddlmZ ddlZddlZddlZddlmZmZm Z m
Z
mZmZ G dd deZ
dd Zd
d Zdd
ZdS )z8 Lockfile behaviour implemented via Unix PID files.
)absolute_importN )LockBase
AlreadyLocked
LockFailed NotLocked NotMyLockLockTimeoutc @ sL e Zd ZdZdddZdd Zdd Zd
d Zddd
Zdd Z dd 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')
FNc C s t | |d| | j| _d S )NF)r __init__pathZunique_name)selfr Zthreadedtimeout r /pidlockfile.pyr $ s zPIDLockFile.__init__c C s
t | jS )z- Get the PID from the lock file.
)read_pid_from_pidfiler r
r r r read_pid* s zPIDLockFile.read_pidc C s t j| jS )zv Test if the lock is currently held.
The lock is held if the PID file for this lock exists.
)osr existsr r r r is_locked/ s zPIDLockFile.is_lockedc C s | ot | 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.
)r r getpidr r r r r i_am_locking7 s zPIDLockFile.i_am_lockingc
C s |dk r|n| j }t }|dk r2|dkr2||7 }zt| j W n tk
r } zt|jtjkrt |kr|dk r|dkrtd| j ntd| j t |dk r|d pd nt
d| j W 5 d}~X Y q2X dS q2dS )z Acquire the lock.
Creates the PID file for this lock, or raises an error if
the lock could not be acquired.
Nr z&Timeout waiting to acquire lock for %sz%s is already locked
g?zfailed to create %s)r timewrite_pid_to_pidfiler OSErrorerrnoZEEXISTr r sleepr )r
r Zend_timeexcr r r acquire? s&