← back to Atmos Game

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

109 lines

�

c�bj$����dZddlmZddlZddlZddlZddlmZddlm	Z	m
Z
mZddlm
Z
e	rddlmZmZdd	lmZdd
lmZe
d�Zed�ZGd
�d�ZGd�d�ZddgZy)zIAsync wrapper around :class:`SoftReadWriteLock` for use with ``asyncio``.�)�annotationsN)�asynccontextmanager)�
TYPE_CHECKING�	ParamSpec�TypeVar�)�SoftReadWriteLock)�AsyncGenerator�Callable)�futures)�
TracebackType�_P�_Rc	�@�eZdZdZ	ddddddddd�																			dd�Zedd��Zedd	��Zedd
��Zedd��Z	edd��Z
eddd
�d d��Zeddd
�d d��Z
	ddd
�					d!d�Z	ddd
�					d!d�Zdd�d"d�Zd#d�Zd#d�Zd$d�Zy)%�AsyncSoftReadWriteLocka�
    Async wrapper around :class:`SoftReadWriteLock` for ``asyncio`` applications.

    The sync class's blocking filesystem operations run on a thread pool via ``loop.run_in_executor()``. The
    underlying :class:`SoftReadWriteLock` handles reentrancy, upgrade/downgrade rules, fork handling, heartbeat and
    TTL stale detection, and singleton behavior.

    :param lock_file: path to the lock file; sidecar state/write/readers live next to it
    :param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
    :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately on contention
    :param is_singleton: if ``True``, reuse existing :class:`SoftReadWriteLock` instances per resolved path
    :param heartbeat_interval: seconds between heartbeat refreshes; default 30 s
    :param stale_threshold: seconds of mtime inactivity before a marker is stale; defaults to ``3 * heartbeat_interval``
    :param poll_interval: seconds between acquire retries under contention; default 0.25 s
    :param loop: event loop for ``run_in_executor``; ``None`` uses the running loop
    :param executor: executor for ``run_in_executor``; ``None`` uses the default executor

    .. versionadded:: 3.27.0

    Tg>@Ng�?)�blocking�is_singleton�heartbeat_interval�stale_threshold�
poll_interval�loop�executorc	��tj�|_t|||||||��|_||_|	|_y)N)rrrrr)�os�getpid�_creator_pidr	�_lock�_loop�	_executor)
�self�	lock_file�timeoutrrrrrrrs
          �o/Users/macstudio3/Projects/atmos-game/assets/gen/.venv/lib/python3.12/site-packages/filelock/_soft_rw/_async.py�__init__zAsyncSoftReadWriteLock.__init__,sC���I�I�K���&����%�1�+�'�
��
���
�!���c�.�|jjS)z4The path to the lock file passed to the constructor.)rr!�r s r#r!z AsyncSoftReadWriteLock.lock_fileFs���z�z�#�#�#r%c�.�|jjS)z\The default timeout applied when ``acquire_read`` / ``acquire_write`` is called without one.)rr"r's r#r"zAsyncSoftReadWriteLock.timeoutKs���z�z�!�!�!r%c�.�|jjS)zYWhether ``acquire_*`` defaults to blocking; ``False`` makes contention raise immediately.)rrr's r#rzAsyncSoftReadWriteLock.blockingPs���z�z�"�"�"r%c��|jS)zNThe event loop used for ``run_in_executor``, or ``None`` for the running loop.)rr's r#rzAsyncSoftReadWriteLock.loopUs���z�z�r%c��|jS)zPThe executor used for ``run_in_executor``, or ``None`` for the default executor.)rr's r#rzAsyncSoftReadWriteLock.executorZs���~�~�r%�rc��K�|j||���d{���	d���|j��d{���y7�#7�#|j��d{���7wxYw�w)a�
        Async context manager that acquires and releases a shared read lock.

        :param timeout: maximum wait time in seconds, or ``None`` to use the instance default
        :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default

        :raises RuntimeError: if a write lock is already held on this instance
        :raises Timeout: if the lock cannot be acquired within *timeout* seconds

        r,N)�acquire_read�release�r r"rs   r#�	read_lockz AsyncSoftReadWriteLock.read_lock_sR��������(��;�;�;�	!���,�,�.� � �		<��
!��$�,�,�.� � ��>�A�=�A�A�A�?�A�A�A�A�A�Ac��K�|j||���d{���	d���|j��d{���y7�#7�#|j��d{���7wxYw�w)a�
        Async context manager that acquires and releases an exclusive write lock.

        :param timeout: maximum wait time in seconds, or ``None`` to use the instance default
        :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default

        :raises RuntimeError: if a read lock is already held, or a write lock is held by a different thread
        :raises Timeout: if the lock cannot be acquired within *timeout* seconds

        r,N)�
acquire_writer/r0s   r#�
write_lockz!AsyncSoftReadWriteLock.write_lockqsR����� � ��8� �<�<�<�	!���,�,�.� � �		=��
!��$�,�,�.� � �r2c��K�|j�|j|jj||���d{���t	|��S7��w)a.
        Acquire a shared read lock.

        See :meth:`SoftReadWriteLock.acquire_read` for reentrancy / upgrade / fork semantics. The blocking work runs
        inside ``run_in_executor`` so other coroutines on the same loop keep progressing while this call waits.

        :param timeout: maximum wait time in seconds, or ``None`` to use the instance default
        :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default

        :returns: a proxy usable as an async context manager to release the lock

        :raises RuntimeError: if a write lock is already held, if this instance was invalidated by
            :func:`os.fork`, or if :meth:`close` was called
        :raises Timeout: if the lock cannot be acquired within *timeout* seconds

        r,N��lock)�_raise_if_inherited�_runrr.�$AsyncAcquireSoftReadWriteReturnProxyr0s   r#r.z#AsyncSoftReadWriteLock.acquire_read�sG����&	
� � �"��i�i��
�
�/�/��8�i�L�L�L�3��>�>�	M���<A�A�Ac��K�|j�|j|jj||���d{���t	|��S7��w)a
        Acquire an exclusive write lock.

        See :meth:`SoftReadWriteLock.acquire_write` for the two-phase writer-preferring semantics. The blocking work
        runs inside ``run_in_executor``.

        :param timeout: maximum wait time in seconds, or ``None`` to use the instance default
        :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default

        :returns: a proxy usable as an async context manager to release the lock

        :raises RuntimeError: if a read lock is already held, if a write lock is held by a different thread, if
            this instance was invalidated by :func:`os.fork`, or if :meth:`close` was called
        :raises Timeout: if the lock cannot be acquired within *timeout* seconds

        r,Nr7)r9r:rr4r;r0s   r#r4z$AsyncSoftReadWriteLock.acquire_write�sG����&	
� � �"��i�i��
�
�0�0�'�H�i�M�M�M�3��>�>�	N�r<F��forcec��K�|jtj�k(r0|j|jj
|���d{���yy7��w)z�
        Release one level of the current lock.

        :param force: if ``True``, release the lock completely regardless of the current lock level

        :raises RuntimeError: if no lock is currently held and *force* is ``False``

        r>N)rrrr:rr/)r r?s  r#r/zAsyncSoftReadWriteLock.release�sD��������	�	��+��)�)�D�J�J�.�.�e�)�<�<�<�,�<�s�AA�A�Ac��K�|jtj�k(r.|j|jj
��d{���yy7��w)zRRelease any held lock and release the underlying filesystem resources. Idempotent.N)rrrr:r�closer's r#rBzAsyncSoftReadWriteLock.close�s>��������	�	��+��)�)�D�J�J�,�,�-�-�-�,�-�s�A
A�A�
Ac�|�|jtj�k7rd|j�d�}t	|��y)NzAsyncSoftReadWriteLock on z4 was inherited across fork; construct a new instance)rrrr!�RuntimeError)r �msgs  r#r9z*AsyncSoftReadWriteLock._raise_if_inherited�s:������	�	��+�.�t�~�~�.>�>r�s�C��s�#�#�,r%c���K�|jxstj�}|j|jtj|g|��i|����d{���S7��w�N)r�asyncio�get_running_loop�run_in_executorr�	functools�partial)r �func�args�kwargsrs     r#r:zAsyncSoftReadWriteLock._run�sQ�����z�z�7�W�5�5�7���)�)�$�.�.�)�:K�:K�D�:b�SW�:b�[a�:b�c�c�c�c�s�AA"�A �A")�����)r!zstr | os.PathLike[str]r"�floatr�boolrrRrrQr�float | NonerrQr� asyncio.AbstractEventLoop | Noner�futures.Executor | None�return�None)rV�str)rVrQ)rVrR)rVrT)rVrUrG)r"rSr�bool | NonerVzAsyncGenerator[None])r"rSrrYrVr;)r?rRrVrW)rVrW)rMzCallable[_P, _R]rNz_P.argsrOz	_P.kwargsrVr)�__name__�
__module__�__qualname__�__doc__r$�propertyr!r"rrrrr1r5r.r4r/rBr9r:�r%r#rrs����0�"�
�!�$(�(,�#�15�,0�"�)�"��"�
�"��
"�"�"�&�"��"�/�"�*�"�
�"�4�$��$��"��"��#��#����������!�W[�!��!�"�!�X\�!��!�$'+�?�GK�?�#�?�9D�?�	-�?�0'+�?�GK�?�#�?�9D�?�	-�?�..3�
=�.�
$�
dr%rc�8�eZdZdZdd�Zdd�Z								dd�Zy)	r;zTAsync context-aware object that releases an :class:`AsyncSoftReadWriteLock` on exit.c��||_yrGr7)r r8s  r#r$z-AsyncAcquireSoftReadWriteReturnProxy.__init__�s	����	r%c��"K�|jS�wrGr7r's r#�
__aenter__z/AsyncAcquireSoftReadWriteReturnProxy.__aenter__�s�����y�y��s�
c��TK�|jj��d{���y7��wrG)r8r/)r �exc_type�	exc_value�	tracebacks    r#�	__aexit__z.AsyncAcquireSoftReadWriteReturnProxy.__aexit__�s�����i�i���!�!�!�s�(�&�(N)r8rrVrW)rVr)reztype[BaseException] | NonerfzBaseException | NonergzTracebackType | NonerVrW)rZr[r\r]r$rcrhr_r%r#r;r;�s:��^���"�,�"�(�"�(�	"�

�"r%r;)r]�
__future__rrHrKr�
contextlibr�typingrrr�_syncr	�collections.abcr
r�
concurrentr�typesr
rrrr;�__all__r_r%r#�<module>rqsf��O�"���	�*�4�4�$��8�"�#��t�_���T�]��sd�sd�l"�"�&+���r%