o
    7Di\
                     @   sP   d dl mZ d dlZd dlZddlmZmZmZmZm	Z	m
Z
 G dd deZdS )    )absolute_importN   )LockBase
LockFailed	NotLocked	NotMyLockLockTimeoutAlreadyLockedc                   @   s:   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdS )LinkLockFilezLock access to a file using atomic property of link(2).

    >>> lock = LinkLockFile('somefile')
    >>> lock = LinkLockFile('somefile', threaded=False)
    Nc                 C   s  z
t | jd  W n ty   td| j w |d ur|n| j}t }|d ur2|dkr2||7 }	 zt| j| j	 W d S  t
y   t| jj}|dkrSY d S |d urut |krut| j |dkrntd| j td| j t|d ur|d pd	 Y nw q3)
Nwbzfailed to create %sr   T   z&Timeout waiting to acquire lock for %sz%s is already locked
   g?)openunique_namecloseIOErrorr   timeouttimeoslink	lock_fileOSErrorstatst_nlinkunlinkr   pathr	   sleep)selfr   end_timenlinks r    N/var/www/Datamplify/venv/lib/python3.10/site-packages/lockfile/linklockfile.pyacquire   s:   zLinkLockFile.acquirec                 C   sN   |   std| j tj| jstd| j t| j t| j d S )Nz%s is not lockedz%s is locked, but not by me)		is_lockedr   r   r   existsr   r   r   r   r   r    r    r!   release7   s   zLinkLockFile.releasec                 C   s   t j| jS N)r   r   r$   r   r%   r    r    r!   r#   ?   s   zLinkLockFile.is_lockedc                 C   s(   |   otj| jot| jjdkS )Nr   )r#   r   r   r$   r   r   r   r%   r    r    r!   i_am_lockingB   s
   zLinkLockFile.i_am_lockingc                 C   s"   t j| jrt | j d S d S r'   )r   r   r$   r   r   r%   r    r    r!   
break_lockG   s   zLinkLockFile.break_lockr'   )	__name__
__module____qualname____doc__r"   r&   r#   r(   r)   r    r    r    r!   r
   
   s    
&r
   )
__future__r   r   r    r   r   r   r   r   r	   r
   r    r    r    r!   <module>   s
     