Your IP : 18.118.252.215
B
���a� � @ s� d dl mZ d dlZd dlZd dlZd dlZd dlmZmZ d dl m
Z
d dlmZ d dl
mZ ddlmZ e�d �ZG d
d� d�ZG dd
� d
e�Zd
dgZdS )� )�annotationsN)�ABC�abstractmethod)�Lock)�
TracebackType)�Any� )�TimeoutZfilelockc @ sB e Zd ZdZddd�dd�Zdd�dd �Zd
dddd
�dd�ZdS )�AcquireReturnProxyzDA context aware object that will release the lock file when exiting.�BaseFileLock�None)�lock�returnc C s
|| _ d S )N)r
)�selfr
� r �>/opt/alt/python37/lib/python3.7/site-packages/filelock/_api.py�__init__ s zAcquireReturnProxy.__init__)r c C s | j S )N)r
)r r r r � __enter__ s zAcquireReturnProxy.__enter__ztype[BaseException] | NonezBaseException | NonezTracebackType | None)�exc_type� exc_value� tracebackr c C s | j �� d S )N)r
�release)r r r r r r r �__exit__ s zAcquireReturnProxy.__exit__N)�__name__�
__module__�__qualname__�__doc__r r r r r r r r
s r
c @ s� e Zd ZdZd/dddd�dd�Zed d
�dd��Zedd
�d
d��Zejddd�dd��Ze dd
�dd��Z
e dd
�dd��Zedd
�dd��Zd0dd�ddddd�dd �Z
d1ddd"�d#d$�Zd d
�d%d&�Zd'd(d)dd*�d+d,�Zdd
�d-d.�ZdS )2r z+Abstract base class for a file lock object.���zstr | os.PathLike[Any]�floatr )� lock_file�timeoutr c C s* t �|�| _d| _|| _t� | _d| _dS )a�
Create a new lock object.
:param lock_file: path to the file
:param timeout: default timeout when acquiring the lock. It will be used as fallback value in the acquire
method, if no timeout value (``None``) is given. If you want to disable the timeout, set it to a negative value.
A timeout of 0 means, that there is exactly one attempt to acquire the file lock.
Nr )�os�fspath�
_lock_file�
_lock_file_fdr r �_thread_lock�
_lock_counter)r r r r r r r ) s
zBaseFileLock.__init__�str)r c C s | j S )z:return: path to the lock file)r# )r r r r r C s zBaseFileLock.lock_filec C s | j S )zU
:return: the default timeout value
.. versionadded:: 2.0.0
)�_timeout)r r r r r H s zBaseFileLock.timeoutzfloat | str)�valuer c C s t |�| _dS )zX
Change the default timeout value.
:param value: the new value
N)r r( )r r) r r r r Q s c C s t �dS )zbIf the file lock could be acquired, self._lock_file_fd holds the file descriptor of the lock file.N)�NotImplementedError)r r r r �_acquireZ s zBaseFileLock._acquirec C s t �dS )z6Releases the lock and sets self._lock_file_fd to None.N)r* )r r r r �_release_ s zBaseFileLock._release�boolc C s
| j dk S )z�
:return: A boolean indicating if the lock file is holding the lock currently.
.. versionchanged:: 2.0.0
This was previously a method and is now a property.
N)r$ )r r r r � is_lockedd s
zBaseFileLock.is_lockedN皙�����?)�poll_intervallzfloat | Noner
)r �
poll_intervalr0 r c C sT |dkr| j }|dk r.d}tj|tdd� |}| j� | jd7 _W dQ R X t| �}| j}t�� }y�x�| j�" | j s�t
�d||� | �� W dQ R X | j r�t
�d||� P qhd| kr�t�� | k r�n nt
�d ||� t
| j��qhd
}t
�||||� t�|� qhW W n< tk
�rH | j� td| jd �| _W dQ R X � Y nX t| d�S )az
Try to acquire the file lock.
:param timeout: maximum wait time for acquiring the lock, ``None`` means use the default :attr:`~timeout` is and
if ``timeout < 0``, there is no timeout and this method will block until the lock could be acquired
:param poll_interval: interval of trying to acquire the lock file
:param poll_intervall: deprecated, kept for backwards compatibility, use ``poll_interval`` instead
:raises Timeout: if fails to acquire lock within the timeout period
:return: a context object that will unlock the file when the context is exited
.. code-block:: python
# You can use this method in the context manager (recommended)
with lock.acquire():
pass
# Or use an equivalent try-finally construct:
lock.acquire()
try:
pass
finally:
lock.release()
.. versionchanged:: 2.0.0
This method returns now a *proxy* object instead of *self*,
so that it can be used in a with statement without side effects.
Nz+use poll_interval instead of poll_intervall� )�
stacklevelr z#Attempting to acquire lock %s on %szLock %s acquired on %sr z"Timeout on acquiring lock %s on %sz2Lock %s not acquired on %s, waiting %s seconds ...)r
)r �warnings�warn�DeprecationWarningr% r&