Your IP : 216.73.216.196


Current Path : /opt/alt/python35/lib/python3.5/site-packages/fasteners/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/fasteners/__pycache__/process_lock.cpython-35.pyc



V�EV�!�@s�ddlZddlZddlZddlZddlZddlZddlmZeje	�Z
dd�ZGdd�de�Z
Gdd�de
�ZGd	d
�d
e
�Zejdkr�ddlZeZnddlZeZdd
�ZdS)�N)�_utilscCs�ytj|�Wnotk
r�}zO|jtjkrWtjj|�sP�qpdSn|jtjkrmdS�WYdd}~XnXdSdS)zfCreate a directory (and any ancestor directories required).

    :param path: Directory to create
    FNT)�os�makedirs�OSError�errno�EEXIST�path�isdirZEISDIR)r�e�r�G/opt/alt/python35/lib/python3.5/site-packages/fasteners/process_lock.py�_ensure_treesr
c@s�eZdZdZdZdZejddd�Zdd�Z	d	d
�Z
deeddd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)�_InterProcessLockaTAn interprocess locking implementation.

    This is a lock implementation which allows multiple locks, working around
    issues like http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=632857 and
    does not require any cleanup. Since the lock is always held on a file
    descriptor rather than outside of the process, the lock gets dropped
    automatically if the process crashes, even if ``__exit__`` is not
    executed.

    There are no guarantees regarding usage by multiple threads in a
    single process here. This lock works only between processes.

    Note these locks are released when the descriptor is closed, so it's not
    safe to close the file descriptor while another thread holds the
    lock. Just opening and closing the lock file can break synchronization,
    so lock files must be accessed only using this abstraction.
    g�������?g{�G�z�?NcCs=d|_||_d|_||_tj|t�|_dS)NF)�lockfiler�acquired�
sleep_funcrZpick_first_not_none�LOG�logger)�selfrrrrrr�__init__Us
				z_InterProcessLock.__init__cCs�y|j�Wn�tk
r�}zh|jtjtjfkrd|sQ|j�rUdStj��n"tj	dd|j
d|i��WYdd}~XnXdSdS)NFz9Unable to acquire lock on `%(path)s` due to %(exception)sr�	exceptionT)�trylock�IOErrorrZEACCES�EAGAINZexpiredrZ
RetryAgain�	threading�ThreadErrorr)r�blocking�watchr
rrr�_try_acquire\s		#z_InterProcessLock._try_acquirecCsztjj|j�}|rFt|�}|rF|jjtjd|�|jdksa|jj	rvt
|jd�|_dS)NzCreated lock base path `%s`�a)rr�dirnamer
r�logr�BLATHERr�closed�open)rZbasedirZmade_basedirrrr�_do_openps
z_InterProcessLock._do_openTc
Cs�|dkrtd��|dk	r<|dkr<td��||krN|}|j�tjd|�}tj||d|jd|�}|�||j||�}WdQRX|s�d|_dSd	|_|jj	tj
d
|j|j�|j
�d	SdS)a�Attempt to acquire the given lock.

        :param blocking: whether to wait forever to try to acquire the lock
        :type blocking: bool
        :param delay: when blocking this is the delay time in seconds that
                      will be added after each failed acquisition
        :type delay: int/float
        :param max_delay: the maximum delay to have (this limits the
                          accumulated delay(s) added after each failed
                          acquisition)
        :type max_delay: int/float
        :param timeout: an optional timeout (limits how long blocking
                        will occur for)
        :type timeout: int/float
        :returns: whether or not the acquisition succeeded
        :rtype: bool
        rz+Delay must be greater than or equal to zeroNz-Timeout must be greater than or equal to zeroZdurationrrFTzHAcquired file lock `%s` after waiting %0.3fs [%s attempts were required])�
ValueErrorr%rZ	StopWatchZRetryrrrrr!r"r�elapsedZattempts)rr�delayZ	max_delay�timeoutr�rZgottenrrr�acquire}s*
		z_InterProcessLock.acquirecCs)|jdk	r%|jj�d|_dS)N)r�close)rrrr�	_do_close�s
z_InterProcessLock._do_closecCs|j�|S)N)r+)rrrr�	__enter__�s
z_InterProcessLock.__enter__cCs�|jstjd��y|j�Wn(tk
rP|jjd|j�Yn_Xd|_y|j�Wn(tk
r�|jjd|j�YnX|jj	t
jd|j�dS)z%Release the previously acquired lock.z$Unable to release an unacquired lockz1Could not unlock the acquired lock opened on `%s`Fz.Could not close the file handle opened on `%s`z*Unlocked and closed file lock open on `%s`N)rrr�unlockrrrrr-r!rr")rrrr�release�s 	
	
z_InterProcessLock.releasecCs|j�dS)N)r0)r�exc_typeZexc_val�exc_tbrrr�__exit__�sz_InterProcessLock.__exit__cCstjj|j�S)z<Checks if the path that this lock exists at actually exists.)rr�exists)rrrrr4�sz_InterProcessLock.existscCs
t��dS)N)�NotImplementedError)rrrrr�sz_InterProcessLock.trylockcCs
t��dS)N)r5)rrrrr/�sz_InterProcessLock.unlock)�__name__�
__module__�__qualname__�__doc__Z	MAX_DELAYZDELAY_INCREMENT�time�sleeprrr%r+r-r.r0r3r4rr/rrrrr4s 
)rc@s.eZdZdZdd�Zdd�ZdS)�_WindowsLockz?Interprocess lock implementation that works on windows systems.cCs#tj|jj�tjd�dS)N�)�msvcrt�lockingr�filenoZLK_NBLCK)rrrrr�sz_WindowsLock.trylockcCs#tj|jj�tjd�dS)Nr=)r>r?rr@ZLK_UNLCK)rrrrr/�sz_WindowsLock.unlockN)r6r7r8r9rr/rrrrr<�sr<c@s.eZdZdZdd�Zdd�ZdS)�
_FcntlLockz=Interprocess lock implementation that works on posix systems.cCs!tj|jtjtjB�dS)N)�fcntl�lockfrZLOCK_EXZLOCK_NB)rrrrr�sz_FcntlLock.trylockcCstj|jtj�dS)N)rBrCrZLOCK_UN)rrrrr/�sz_FcntlLock.unlockN)r6r7r8r9rr/rrrrrA�srA�ntcs"t|���fdd�}|S)zSAcquires & releases a interprocess lock around call into
       decorated function.cs(tj����fdd��}|S)Nc
s���||�SWdQRXdS)Nr)�args�kwargs)�f�lockrr�wrapper�sz7interprocess_locked.<locals>.decorator.<locals>.wrapper)�six�wraps)rGrI)rH)rGr�	decorator�s$z&interprocess_locked.<locals>.decorator)�InterProcessLock)rrLr)rHr�interprocess_locked�s	rN)rZloggingrrr:rJ�	fastenersrZ	getLoggerr6rr
�objectrr<rA�namer>rMrBrNrrrr�<module>s"�