%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/uaclient/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/uaclient/__pycache__/lock.cpython-312.pyc

�

�ϴf���F�ddlZddlZddlZddlmZddlmZmZmZddl	m
Z
mZmZddl
mZddlmZmZddlmZddlmZej,ej.e��ZGd	�d
e
�Zeeedd�
�ej6�Zdeeeffd�Zd�Z Gd�d�Z!y)�N)�Tuple)�
exceptions�system�util)�
DataObject�Field�StringDataValue)�notices)�DataObjectFile�DataObjectFileFormat)�UAFile)�Noticec�@�eZdZede�ede�gZdedefd�Zy)�LockData�lock_pid�lock_holderc� �||_||_y�N�rr)�selfrrs   �//usr/lib/python3/dist-packages/uaclient/lock.py�__init__zLockData.__init__s�� ��
�&���N)�__name__�
__module__�__qualname__rr	�fields�strr�rrrrs0��
�j�/�*�
�m�_�-��F�
'��'�3�'rr�lockF)�private�returnc�F�	tj�}d}|s|S|j}|j}	tjd|g�t|�|fS#tj$r%tjtj
���wxYw#tj$rytj�s&tjd||�t|�|fcYStj!d||�tj"tj
�|cYSwxYw)aReturn lock info if lock file is present the lock is active.

    If process claiming the lock is no longer present, remove the lock file
    and log a warning.

    :return: A tuple (pid, string describing lock holder)
        If no active lock, pid will be -1.
    )�lock_file_path)�����psz.Found stale lock file previously held by %s:%sz1Removing stale lock file previously held by %s:%s)�lock_data_file�readr�InvalidFileFormatError�InvalidLockFile�pathrrr�subp�int�ProcessExecutionErrorr�we_are_currently_root�LOG�debug�warning�ensure_file_absent)�
lock_data_obj�no_lockrrs    r�check_lock_infor7"s��M�&�+�+�-�
��G�����%�%�H��+�+�K�����T�8�$�%��H�
�{�+�+���,�,�M��(�(��8K�8K�L�L�M���+�+���)�)�+��I�I�@���
�
��M�;�/�/����?���	
�
	�!�!�.�"5�"5�6����s#�A�#B�8B�AD �!<D �D c�,�tj�yr)r(�deleterrr�clear_lock_file_if_presentr:Ls�����rc�>�eZdZdZddd�dededefd�Zd	�Zd
�Zd�Z	y)
�	RetryLockah
    Context manager for gaining exclusive access to the lock file.

    Create a lock file if absent. The lock file will contain a pid of the
    running process, and a customer-visible description of the lock holder.

    The RetryLock will try several times to acquire the lock before giving up.
    The number of times to try and how long to sleep in between tries is
    configurable.

    :param lock_holder: String with the service name or command which is
        holding the lock. This lock_holder string will be customer visible in
        status.json.
    :param sleep_time: Number of seconds to sleep before retrying if the lock
        is already held.
    :param max_retries: Maximum number of times to try to grab the lock before
        giving up and raising a LockHeldError.
    :raises: LockHeldError if lock is held after (sleep_time * max_retries)
    �
�)�
sleep_time�max_retriesrr?r@c�.�||_||_||_yr)rr?r@)rrr?r@�_argss     rrzRetryLock.__init__es��'���$���&��rc�T�t�\}}|dkDr"tj|j||���tjt
ttj��|j���tjtj|j��y)Nr)�lock_requestr�pidr)�	operation)r7r�
LockHeldErrorrr(�writerr�os�getpidr
�addr�OPERATION_IN_PROGRESS)rr�cur_lock_holders   r�	grab_lockzRetryLock.grab_lockps���&5�&7�#��?��a�<��*�*�!�-�-�+���
�
	����c�"�)�)�+�.�D�<L�<L�M�	
�	����(�(��&�&�	
rc�`�tjd|j�d}		|j�y#tj
$rc}tjd|dz|j�|dz
}||jk\r|�tj|j�Yd}~nd}~wwxYw��)Nzspin lock starting for %srz%RetryLock Attempt %d. %s. Spinning...�)r1r2rrNrrG�msgr@�time�sleepr?)r�tries�es   r�	__enter__zRetryLock.__enter__�s����	�	�-�t�/?�/?�@����
0���� ����+�+�
0��	�	�;�U�Q�Y�������
���D�,�,�,��G��J�J�t���/�/��
0��	s�6�B,�	AB'�'B,c�r�tj�tjtj
�yr)r(r9r
�removerrL)r�	_exc_type�
_exc_value�
_tracebacks    r�__exit__zRetryLock.__exit__�s ���������v�3�3�4rN)
rrr�__doc__rr.rrNrVr\rrrr<r<PsA���0��	'��	'��		'�
�	'�
� 0�"5rr<)"�loggingrIrR�typingr�uaclientrrr�uaclient.data_typesrrr	�uaclient.filesr
�uaclient.files.data_typesrr�uaclient.files.filesr
�uaclient.files.noticesr�	getLogger�replace_top_level_logger_namerr1r�JSONr(r.rr7r:r<rrr�<module>ris����	���-�-�B�B�"�J�'�)��g���:��:�:�8�D�E��'�z�'� ��
�6�5�!������'��s�C�x��'�T�C5�C5r

Zerion Mini Shell 1.0