File: //usr/lib/python3/dist-packages/lockfile/__pycache__/pidlockfile.cpython-310.pyc
o
��UV� � @ st d Z ddlmZ ddlZddlZddlZddlmZmZm Z m
Z
mZmZ G dd� de�Z
dd � Zd
d� Zdd
� ZdS )z8 Lockfile behaviour implemented via Unix PID files.
� )�absolute_importN� )�LockBase�
AlreadyLocked�
LockFailed� NotLocked� NotMyLock�LockTimeoutc @ sL e Zd ZdZddd�Zdd� 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__�path�unique_name)�selfr �threaded�timeout� r �6/usr/lib/python3/dist-packages/lockfile/pidlockfile.pyr $ s zPIDLockFile.__init__c C s
t | j�S )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�| j�S )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� |dur|n| j }t�� }|dur|dkr||7 } zt| j� W dS tyk } z=|jtjkrZt�� |krL|durE|dkrEtd| j ��td| j ��t� |durV|d pWd� nt
d| j ��W Y d}~nd}~ww q) z� Acquire the lock.
Creates the PID file for this lock, or raises an error if
the lock could not be acquired.
Nr Tz&Timeout waiting to acquire lock for %sz%s is already locked�
g�������?zfailed to create %s)r �time�write_pid_to_pidfiler �OSError�errno�EEXISTr r �sleepr )r r �end_time�excr r r �acquire? s0 �������zPIDLockFile.acquirec C s: | � � std| j ��| �� std| j ��t| j� dS )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)r r r r r �remove_existing_pidfiler r r r �release_ s
zPIDLockFile.releasec C s t | j� dS )z� Break an existing lock.
Removes the PID file if it already exists, otherwise does
nothing.
N)r% r r r r r �
break_lockl s zPIDLockFile.break_lock)FN)N)�__name__�
__module__�__qualname__�__doc__r r r r r$ r&