← back to Atmos Game

assets/gen/.venv/lib/python3.12/site-packages/filelock/__pycache__/_lease.cpython-312.pyc

98 lines

�

c�bj�8����ddlmZddlZddlZddlZddlmZddlmZddl	m
Z
mZmZm
Z
ddlmZmZddlmZdd	lmZdd
lmZmZmZmZddlmZddlmZmZer,ddlZdd
l m!Z!ddl"m#Z#ejHdk\rddlm%Z%nddl&m%Z%edZ'edZ(ed��Gd�d��Z)ed��Gd�d��Z*eGd�d��Z+Gd�d�Z,Gd�de,e
�Z-Gd�d e�Z.gd!�Z/y)"�)�annotationsN)�suppress)�	dataclass)�Event�Thread�current_thread�local)�
TYPE_CHECKING�Literal�)�LeaseSettingsMismatch)�owner_is_stale)�MarkerSoftFileLock�	OwnerMode�OwnerRecord�parse_marker)�_read_lock_file)�break_lock_file�touch)�Callable)�LockOptions)��)�Unpack)�marker-missing�
owner-changed�refresh-failed)�ok�lost�	transientT)�frozenc�>�eZdZUdZded<ded<ded<dZded	<y)
�LeaseCompromisez6Why a held lease stopped being this process's to hold.�str�	lock_file�token�CompromiseReason�reasonN�OSError | None�error)�__name__�
__module__�__qualname__�__doc__�__annotations__r*���f/Users/macstudio3/Projects/atmos-game/assets/gen/.venv/lib/python3.12/site-packages/filelock/_lease.pyr#r#!s��@��N��J��� �E�>� r1r#c�&�eZdZUdZded<ded<y)�
_HeartbeatzPA running heartbeat and the event that stops it, which only ever exist together.r�threadr�stopN)r+r,r-r.r/r0r1r2r4r4+s��Z��N�
�Kr1r4c�<�eZdZUdZdZded<dZded<dZded<y)	�_LeaseClaimzNThe state of one claim: its token, its heartbeat, and how that claim was lost.N�
str | Noner&�LeaseCompromise | None�
compromisez_Heartbeat | None�	heartbeat)r+r,r-r.r&r/r;r<r0r1r2r8r83s%��X��E�:��)-�J�&�-�#'�I� �'r1r8c��eZdZdZdd�Zy)�_LeaseClaimHolderz,Holds the claim its owning context acquired.c�"�t�|_y�N)r8�claim��selfs r2�__init__z_LeaseClaimHolder.__init__Bs�� �]��
r1N��return�None)r+r,r-r.rDr0r1r2r>r><s
��6�
#r1r>c��eZdZdZy)�_ThreadLocalLeaseClaimHolderz:A thread local version of the ``_LeaseClaimHolder`` class.N)r+r,r-r.r0r1r2rIrIFs��Dr1rIc�X��eZdZUdZdZded<dZded<dZd	ed
<dddd
�											d�fd�Ze	dd��Z
e	dd��Ze	d d��Ze	d!d��Z
d"�fd�Zd"�fd�Zd#�fd�Zd"�fd�Zd$d�Zd%d�Zd"d�Z												d&d�Z										d'd�Z										d(d�Z�xZS))�
SoftFileLeasea�
    Existence lock whose claim expires, so a peer may take it while the previous holder still runs.

    A lease trades mutual exclusion for progress. The holder publishes a claim and refreshes it every
    ``heartbeat_interval`` seconds; a contender takes the marker once it is ``lease_duration`` seconds stale. Nothing
    stops the expired holder: it keeps running, and it keeps using whatever the lock protects. Treat the lease as a hint
    about who *should* be working, not as a guarantee that only one worker is.

    To make a protected resource reject a superseded holder, that resource must be linearizable and must fence on a
    monotonic generation it controls. :attr:`token` names a claim; it does not fence one. Where overlap is unacceptable,
    use :class:`StrictSoftFileLock <filelock.StrictSoftFileLock>` instead.

    Every contender for a path must agree on ``lease_duration``. A contender that finds a claim published under a
    different duration raises :class:`LeaseSettingsMismatch <filelock.LeaseSettingsMismatch>` rather than apply its own
    expiry to a peer that never agreed to it.

    Expiry reclaims less on Windows, which refuses to rename or delete a file another process holds open. A peer there
    takes an expired claim only once the previous holder's process exits and its handle closes; a holder that lives on
    but stops refreshing keeps the marker. Unix reclaims the marker either way.

    ``on_compromise`` fires from the heartbeat thread when a refresh fails, or when the marker vanishes or names another
    owner. The holder should stop touching the protected resource when it runs. Because it runs on that thread, a
    ``release()`` inside it only takes effect when the lease was built with ``thread_local=False``; the default
    thread-local context hides the claim from every thread but the one that acquired it, so the release does nothing.
    Signal the acquiring thread instead when the context stays thread-local.

    .. versionadded:: 3.30.0

    �leaser�_owner_modeF�bool�_lifetime_supportedz(lease_duration sets when a lease expiresr$�_lifetime_unsupported_reasong>@N)�lease_duration�heartbeat_interval�
on_compromisec�"��|dkrd|��}t|��|�|dz}d|cxkr|ksnd|��}t|��t�|�|fi|��||_||_||_|j
�rt�|_	yt�|_	y)a
        Create a lease.

        :param lease_duration: seconds of marker staleness after which a contender may take the claim. Every contender
            for the path must pass the same value.
        :param heartbeat_interval: seconds between refreshes. Defaults to a third of ``lease_duration``, leaving room
            for two missed refreshes before a peer may take the claim. Must be shorter than ``lease_duration``.
        :param on_compromise: called from the heartbeat thread with a :class:`LeaseCompromise` when the claim is lost.
        :param kwargs: every other :class:`BaseFileLock <filelock.BaseFileLock>` option, ``timeout`` and ``mode`` among
            them. The metaclass passes them all by keyword, and taking them here lets
            :class:`AsyncSoftFileLease <filelock.AsyncSoftFileLease>` add the async plumbing a fixed signature would
            hide.

        rz%lease_duration must be positive, got NrzBheartbeat_interval must be positive and below lease_duration, got )
�
ValueError�superrD�_lease_duration�_heartbeat_interval�_on_compromise�is_thread_localrIr>�_claims)rCr%rQrRrS�kwargs�msg�	__class__s       �r2rDzSoftFileLease.__init__os����.�Q��9�.�9K�L�C��S�/�!��%�!/�!�!3���%�6��6�V�Wi�Vl�m�C��S�/�!�
����-�f�-�-���#5�� �+���
Z�D�,@�,@�,B�(�+���HY�+��r1c�.�|jjSr@)r[rArBs r2�_claimzSoftFileLease._claim�s���|�|�!�!�!r1c��|jS)zEThe staleness in seconds after which a contender may take this claim.)rWrBs r2rQzSoftFileLease.lease_duration�s���#�#�#r1c�.�|jjS)z�
        The token naming the claim this process published.

        :returns: the token while the lease is held, ``None`` otherwise. It identifies a claim; it does not fence one.

        )r`r&rBs r2r&zSoftFileLease.token�s���{�{� � � r1c�.�|jjS)z�
        The loss of claim the heartbeat observed.

        :returns: the :class:`LeaseCompromise`, or ``None`` while the claim still holds

        )r`r;rBs r2r;zSoftFileLease.compromise�s���{�{�%�%�%r1c�.��|j}|j�tjd�x|_}d|_t�|��|jjx}�/|jjx}	�|j||||�yyy)N�)r`�_stop_heartbeat�secrets�	token_hexr&r;rV�_acquire�_context�lock_file_fd�lock_file_fd_identity�_start_heartbeat)rCrAr&�fd�identityr^s     �r2rizSoftFileLease._acquire�s������������%�/�/��3�3���e����
�����-�-�,�,�,�B�9��
�
�;�;�;�H��?�
�!�!�%��X�u�=�?�9r1c�d��|j�d|j_t�|��yr@)rfr`r&rV�_release�rCr^s �r2rqzSoftFileLease._release�s&������� �����
���r1c�~��t�|��j|jj|j
��S)N)r&rQ)rV�_published_record�_replacer`r&rWrrs �r2rtzSoftFileLease._published_record�s2����w�(�*�3�3�$�+�+�:K�:K�\`�\p�\p�3�q�qr1c�d��|j�x}�t�|�	�y|\}}}|jdk7ry|j|j
k7r4|j�d|j�d|j
�d�}t|��tt�5t|j|j|j�r!t|j||�	ddd�ytj�|z
|j
k\rt|j||�ddd�y#1swYyxYw)NrLz holds a lease of z s but this contender configured z:s; every contender for a path must agree on lease_duration)�
_read_peerrV�_try_break_stale_lock�moderQrWr%r
r�OSErrorr�pid�hostname�startr�time)rC�peer�owner�mtime�inor]r^s      �r2rxz#SoftFileLease._try_break_stale_lock�s����O�O�%�%�D�.�

�G�)�+�� ���u�c��:�:�� �����4�#7�#7�7��>�>�"�"4�U�5I�5I�4L�Ll��'�'�*�*d�f�
�(��,�,��g�
��e�i�i�������E������s�;���
��y�y�{�U�"�d�&:�&:�:������s�;��
�
�s�AD&�";D&�&D/c���ttt�5t|j�\}}}t|�x}�|||fcddd�S	ddd�y#1swYyxYwr@)rrzrUrr%r)rC�contentr�r�r�s     r2rwzSoftFileLease._read_peer�s[��
�g�z�
*�"1�$�.�.�"A��G�U�C�%�g�.�.��;��e�S�(�+�
*�;�+��	+��s�+A�Ac���t�}t|j|||||fdtj���d��}t||�|_|j�y)Nzfilelock-lease-T)�target�args�name�daemon)rr�_refresh_until_stopped�os�getpidr4r<r})rCrArnror&r6r5s       r2rmzSoftFileLease._start_heartbeat�sX���w����.�.���X�u�d�3�"�2�9�9�;�-�0��	
��%�V�T�2������r1c���|j}|jx}�y|jj�d|_|jt�ur'|jj
|j��yy)N)�timeout)r`r<r6�setr5r�joinrX)rCrAr<s   r2rfzSoftFileLease._stop_heartbeat�sg���������(�I�1��������������>�#3�3����!�!�$�*B�*B�!�C�4r1c��tj�}|j|j�s�|j	||||�\}}|dk(ry|dk(rtj�}nFtj�|z
|j
|jz
k\r|j
|d||�y|j|j�s��yy)Nrrr)r~�	monotonic�waitrX�_refresh_claimrW�_report_compromise)	rCrArnror&r6�last_success�outcomer*s	         r2r�z$SoftFileLease._refresh_until_stoppeds����~�~�'���)�)�D�4�4�5�!�0�0���H�e�L�N�G�U��&� ���$��#�~�~�/�����!�L�0�D�4H�4H�4�Kc�Kc�4c�c��'�'��/?���N���)�)�D�4�4�5r1c��	tj|j�}|j|jf|k7r|j	|dd|�y	t|j|��y#t$r}|j	|d||�Yd}~yd}~wt
$r}d|fcYd}~Sd}~wwxYw#t
$r}d|fcYd}~Sd}~wwxYw)Nr)rNr r)rn)rN)	r��lstatr%�FileNotFoundErrorr�rz�st_dev�st_inor)rCrArnror&�str*s       r2r�zSoftFileLease._refresh_claims���	&����$�.�.�)�B�
�I�I�r�y�y�!�X�-��#�#�E�?�D�%�H��	&��$�.�.�R�(���!�	 ��#�#�E�+;�U�E�J����	&���%�%��	&���	&���%�%��	&�sG�A*�B)�*	B&�3B�B&�B!�B&�!B&�)	C�2B;�5C�;Cc��t|j|||��|_|j�|j|j�yy)N)r%r&r(r*)r#r%r;rY)rCrAr(r*r&s     r2r�z SoftFileLease._report_compromise6sB��+�T�^�^�5�Y_�gl�m������*����� 0� 0�1�+r1)r%zstr | os.PathLike[str]rQ�floatrRzfloat | NonerSz(Callable[[LeaseCompromise], None] | Noner\zUnpack[LockOptions]rFrG)rFr8)rFr�)rFr9)rFr:rE)rFr)rFz%tuple[OwnerRecord, float, int] | None)
rAr8rn�intro�tuple[int, int]r&r$rFrG)rAr8rnr�ror�r&r$r6rrFrG)
rAr8rnr�ror�r&r$rFz&tuple[_RefreshOutcome, OSError | None])
rAr8r(r'r*r)r&r$rFrG)r+r,r-r.rMr/rOrPrD�propertyr`rQr&r;rirqrtrxrwrmrfr�r�r��
__classcell__)r^s@r2rKrKJs�����<%�K��$�!&���%�(R� �#�R�!%�+/�BF�
'�)�'��	'�
)�'�@�
'�&�'�
�'�R�"��"��$��$��!��!��&��&�>��
r�<�<��D����
��"�	�
���
�
��0���
��"�	�
��
0�
�02��2�!�2��	2�
�2�
�
2r1rK)r'r#rK)0�
__future__rr�rgr~�
contextlibr�dataclassesr�	threadingrrrr	�typingr
r�_errorr
�	_identityr�_markerrrrr�_softr�_utilrr�sys�collections.abcr�_apir�version_infor�typing_extensionsr'�_RefreshOutcomer#r4r8r>rIrK�__all__r0r1r2�<module>r�s���"�	����!�:�:�)�)�%�M�M�"�)���(�!�
���7�"�!�,��N�O���3�4���$��!�!��!��$�������(�(��(�#�#�E�#4�e�E�x2�&�x2�v�r1