[ Root System Explorer ]
Location:
Root
/
proc
/
thread-self
/
root
/
proc
/
thread-self
/
root
/
opt
/
gsutil
/
third_party
/
fasteners
/
fasteners
/
__pycache__
+ Folder
+ File
Upload
Editing: process_lock.cpython-39.pyc
a V�EV�! � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ e�e �Z dd� ZG dd� de�Z G dd� de �ZG d d � d e �Zejdkr�d dlZeZnd dlZeZdd � ZdS )� N)�_utilsc C s� zt �| � W nl tyz } zT|jtjkrJt j�| �s:� qfW Y d}~dS n|jtjkrdW Y d}~dS � W Y d}~nd}~0 0 dS dS )zfCreate a directory (and any ancestor directories required). :param path: Directory to create NFT)�os�makedirs�OSError�errno�EEXIST�path�isdir�EISDIR)r �e� r �;/opt/gsutil/third_party/fasteners/fasteners/process_lock.py�_ensure_tree s r c @ s� e Zd ZdZdZdZejdfdd�Zdd� Z d d � Z deedfdd �Zdd� Zdd� Z dd� Zdd� Zdd� Zdd� Zdd� ZdS )�_InterProcessLockaT An 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�?Nc C s* d | _ || _d| _|| _t�|t�| _d S )NF)�lockfiler �acquired� sleep_funcr �pick_first_not_none�LOG�logger)�selfr r r r r r �__init__U s z_InterProcessLock.__init__c C s� z| � � W np ty| } zX|jtjtjfv rR|r:|�� rHW Y d }~dS t�� �nt� d| j |d� ��W Y d }~nd }~0 0 dS d S )NFz9Unable to acquire lock on `%(path)s` due to %(exception)s)r � exceptionT)�trylock�IOErrorr ZEACCES�EAGAIN�expiredr � RetryAgain� threading�ThreadErrorr )r �blocking�watchr r r r �_try_acquire\ s ��z_InterProcessLock._try_acquirec C sT t j�| j�}|r0t|�}|r0| j�tjd|� | jd u sB| jj rPt | jd�| _d S )NzCreated lock base path `%s`�a)r r �dirnamer r �logr �BLATHERr �closed�open)r ZbasedirZmade_basedirr r r �_do_openp s �z_InterProcessLock._do_openTc C s� |dk rt d��|dur(|dk r(t d��||kr4|}| �� tj|d�}tj||| j|d�}|� || j||�}W d � n1 s�0 Y |s�d| _dS d| _| j� tj d | j|�� |j � dS dS ) 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 r z+Delay must be greater than or equal to zeroNz-Timeout must be greater than or equal to zero)�duration)r r! FTzHAcquired file lock `%s` after waiting %0.3fs [%s attempts were required])� ValueErrorr) r � StopWatch�Retryr r"