CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
asyncio.cpython-310.pyc117 linesDownload Raw Back to __pycache__
1o

2��Yi�0�@s�dZddlmZddlZddlZddlZddlZddlZddlm	Z	ddl3mZddlm
Z
ddlmZmZmZmZdd	lmZmZmZdd4lmZddlmZddlmZdd
lmZer�ddlZddl m!Z!ddl"m#Z#ddl$m%Z%ej&dkr�ddlm'Z'nddl(m'Z'e�)d�Z*e	Gdd�de��Z+Gdd�de+e
�Z,Gdd�d�Z-Gdd�de�Z.Gdd�dee.d�Z/Gdd �d ee/�Z0Gd!d"�d"ee/�Z1Gd#d$�d$ee/�Z2gd%�Z3dS)&z1An asyncio-based implementation of the file lock.�)�annotationsN)�	dataclass)�iscoroutinefunction)�local)�
TYPE_CHECKING�Any�NoReturn�cast�)�BaseFileLock�FileLockContext�FileLockMeta)�Timeout)�SoftFileLock)�UnixFileLock)�WindowsFileLock)�Callable)�futures)�
TracebackType)��)�Self�filelockc@s6eZdZUdZdZded<dZded<dZded	<dS)5�AsyncFileLockContextzGA dataclass which holds the context for a ``BaseAsyncFileLock`` object.T�bool�run_in_executorN�futures.Executor | None�executor� asyncio.AbstractEventLoop | None�loop)�__name__�6__module__�__qualname__�__doc__r�__annotations__rr�r%r%�zE:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\filelock/asyncio.pyr$s78rc@�eZdZdZdS)�AsyncThreadLocalFileContextz8A thread local version of the ``FileLockContext`` class.N�r r!r"r#r%r%r%r&r(2�r(c@s.eZdZdZddd�Zddd	�Zddd�ZdS)�AsyncAcquireReturnProxyzDA context-aware object that will release the lock file when exiting.�lock�BaseAsyncFileLock�return�NonecCs9||_dS�N�r,)�selfr,r%r%r&�__init__9s10z AsyncAcquireReturnProxy.__init__c�s�|jSr0r1�r2r%r%r&�11__aenter__<s�z"AsyncAcquireReturnProxy.__aenter__�exc_type�type[BaseException] | None�	exc_value�BaseException | None�	traceback�TracebackType | Nonec�s�|j��IdHdSr0)r,�release�r2r6r8r:r%r%r&�	__aexit__?s�z!AsyncAcquireReturnProxy.__aexit__N)r,r-r.r/)r.r-�r6r7r8r9r:r;r.r/)r r!r"r#r3r5r>r%r%r%r&r+6s121314r+cs4eZdZ			ddddddd�d�fdd�Z�ZS)�AsyncFileLockMeta������FTN��blocking�is_singletonrrr�	lock_file�str | os.PathLike[str]�timeout�float�mode�int�thread_localrrDrErrrrrr.r-cs<|r15|r16d}17t|18��t�j|||||||||	d�	}td|�S)Nz:run_in_executor is not supported when thread_local is True)	rFrHrJrLrDrErrrr-)�19ValueError�super�__call__r	)�clsrFrHrJrLrDrErrr�msg�instance��	__class__r%r&rOIs
�20zAsyncFileLockMeta.__call__�rArBF)rFrGrHrIrJrKrLrrDrrErrrrrrrr.r-)r r!r"rO�
__classcell__r%r%rSr&r@Hs��r@c@s�eZdZdZ			dBdddddd�dCdd�ZedDdd��ZedEdd��ZejdFd d��ZedGd!d"��Z			#dHdd$�dId)d*�Z21dJdKd,d-�ZdLd0d1�ZdMd3d4�Z
dNd6d7�ZdOd>d?�ZdPd@dA�ZdS)Qr-z'Base class for asynchronous file locks.rArBFTNrCrFrGrHrIrJrKrLrrDrErrrrrr.r/cCsB||_||_t�|�||||||	d�}22|rtntdi|23��|_dS)a"24        Create a new lock object.25 26        :param lock_file: path to the file27        :param timeout: default timeout when acquiring the lock, in seconds. It will be used as fallback value in             the acquire method, if no timeout value (``None``) is given. If you want to disable the timeout, set it             to a negative value. A timeout of 0 means that there is exactly one attempt to acquire the file lock.28        :param mode: file permissions for the lockfile29        :param thread_local: Whether this object's internal context should be thread local or not. If this is set to             ``False`` then the lock will be reentrant across threads.30        :param blocking: whether the lock should be blocking or not31        :param is_singleton: If this is set to ``True`` then only one instance of this class will be created             per lock file. This is useful if you want to use the lock object for reentrant locking without needing             to pass the same object around.32        :param loop: The event loop to use. If not specified, the running event loop will be used.33        :param run_in_executor: If this is set to ``True`` then the lock will be acquired in an executor.34        :param executor: The executor to use. If not specified, the default executor will be used.35 36        )rFrHrJrDrrrNr%)Z_is_thread_localZ
_is_singleton�os�fspathr(r�_context)r2rFrHrJrLrDrErrr�kwargsr%r%r&r3js �	�zBaseAsyncFileLock.__init__cC�|jjS)z"::return: whether run in executor.)rYrr4r%r%r&r��z!BaseAsyncFileLock.run_in_executorcCr[)z::return: the executor.�rYrr4r%r%r&r�r\zBaseAsyncFileLock.executor�valuecCs||j_dS)z�37        Change the executor.38 39        :param value: the new executor or ``None``40        :type value: futures.Executor | None41 42        Nr])r2r^r%r%r&r�s	cCr[)z::return: the event loop.)rYrr4r%r%r&r�r\zBaseAsyncFileLock.loop皙�����?)rD�float | None�
poll_interval�bool | Noner+c�s6�|dur	|jj}|dur|jj}|jjd7_t|�}|j}t��}z^	|js9t	�43d||�|�|j�IdH|jrDt	�44d||�n=|durSt	�45d||�t
|��d|krat��|krnnnt	�46d	||�t
|��d47}t	�48||||�t�|�IdHq&Wnty�td|jjd�|j_�wt|d�S)aW49        Try to acquire the file lock.50 51        :param timeout: maximum wait time for acquiring the lock, ``None`` means use the default52            :attr:`~BaseFileLock.timeout` is and if ``timeout < 0``, there is no timeout and53            this method will block until the lock could be acquired54        :param poll_interval: interval of trying to acquire the lock file55        :param blocking: defaults to True. If False, function will return immediately if it cannot obtain a lock on the56         first attempt. Otherwise, this method will block until the timeout expires or the lock is acquired.57        :raises Timeout: if fails to acquire lock within the timeout period58        :return: a context object that will unlock the file when the context is exited59 60        .. code-block:: python61 62            # You can use this method in the context manager (recommended)63            with lock.acquire():64                pass65 66            # Or use an equivalent try-finally construct:67            lock.acquire()68            try:69                pass70            finally:71                lock.release()72 73        Nr74Tz#Attempting to acquire lock %s on %szLock %s acquired on %sFz+Failed to immediately acquire lock %s on %srz"Timeout on acquiring lock %s on %sz2Lock %s not acquired on %s, waiting %s seconds ...r1)rYrHrD�lock_counter�idrF�time�perf_counter�	is_locked�_LOGGER�debug�_run_internal_methodZ_acquirer�asyncio�sleep�
BaseException�maxr+)r2rHrarD�lock_id�
lock_filename�75start_timerQr%r%r&�acquire�sB�" �76�77zBaseAsyncFileLock.acquire�forcec�sz�|jr9|jjd8_|jjdks|r;t|�|j}}t�d||�|�|j�IdHd|j_t�d||�dSdSdS)a+78        Releases the file lock. Please note, that the lock is only completely released, if the lock counter is 0.79        Also note, that the lock file itself is not automatically deleted.80 81        :param force: If true, the lock counter is ignored and the lock is released in every case/82 83        r84rz#Attempting to release lock %s on %sNzLock %s released on %s)	rgrYrcrdrFrhrirj�_release)r2rsrorpr%r%r&r<�s��zBaseAsyncFileLock.release�method�Callable[[], Any]c�sP�t|�r
|�IdHdS|jr#|jpt��}|�|j|�IdHdS|�dSr0)rrrrk�get_running_loopr)r2rurr%r%r&rj
s�85z&BaseAsyncFileLock._run_internal_methodrcCsd}t|��)z�86        Replace old __enter__ method to avoid using it.87 88        NOTE: DO NOT USE `with` FOR ASYNCIO LOCKS, USE `async with` INSTEAD.89 90        :return: none91        :rtype: NoReturn92        z>Do not use `with` for asyncio locks, use `async with` instead.)�NotImplementedError)r2rQr%r%r&�	__enter__s	zBaseAsyncFileLock.__enter__rc�s�|��IdH|S)zF93        Acquire the lock.94 95        :return: the lock object96 97        N)rrr4r%r%r&r5"s�zBaseAsyncFileLock.__aenter__r6r7r8r9r:r;c�s�|��IdHdS)z�98        Release the lock.99 100        :param exc_type: the exception type if raised101        :param exc_value: the exception value if raised102        :param traceback: the exception traceback if raised103 104        N)r<r=r%r%r&r>,s�zBaseAsyncFileLock.__aexit__cCs|t�t��/|jpt��}|��s|�|jdd��n|�	|jdd��Wd�dSWd�dS1s7wYdS)z'Called when the lock object is deleted.T)rsN)105106contextlib�suppress�RuntimeErrorrrkrwZ107is_runningZrun_until_completer<Zcreate_task)r2rr%r%r&�__del__<s�"�zBaseAsyncFileLock.__del__rU)rFrGrHrIrJrKrLrrDrrErrrrrrrr.r/)r.r)r.r)r^rr.r/)r.r)Nr_)rHr`rarIrDrbr.r+)F)rsrr.r/)rurvr.r/)r.r)r.rr?)r.r/)r r!r"r#r3�propertyrr�setterrrrr<rjryr5r>r}r%r%r%r&r-gs>��2108��D109110	111112 113r-)�	metaclassc@r')�AsyncSoftFileLockz.Simply watches the existence of the lock file.Nr)r%r%r%r&r�Fr*r�c@r')�AsyncUnixFileLockzHUses the :func:`fcntl.flock` to hard lock the lock file on unix systems.Nr)r%r%r%r&r�Jr*r�c@r')�AsyncWindowsFileLockzNUses the :func:`msvcrt.locking` to hard lock the lock file on windows systems.Nr)r%r%r%r&r�Nr*r�)r+r�r�r�r-)4r#�114__future__rrkrz�loggingrWre�dataclassesr�inspectr�	threadingr�typingrrrr	Z_apirrr
�_errorrZ_softrZ_unixr�_windowsr�sys�collections.abcrZ115concurrentr�typesr�version_inforZtyping_extensions�	getLoggerrhrr(r+r@r-r�r�r��__all__r%r%r%r&�<module>sH116117
`
Aluode/PerceptionLabPortable · CoolFace