L i8ddlmZddlZddlZddlZddlZddlZddlZddlm Z m Z ddl m Z ddl mZddlmZmZmZddlmZdd lmZer&ddlZdd lmZej4d k\rdd lmZndd lmZej:d ZGddZe GddZ Gdde eZ!Gdde Z"GddejFe"Z$ddgZ%y)) annotationsN)ABCMetaabstractmethod) dataclass)local) TYPE_CHECKINGAnycast)WeakValueDictionary)Timeout) TracebackType) )Selffilelockc8eZdZdZddZddZ ddZy) AcquireReturnProxyzDA context-aware object that will release the lock file when exiting.c||_yNlock)selfrs S/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/filelock/_api.py__init__zAcquireReturnProxy.__init__$s  c|jSrrrs r __enter__zAcquireReturnProxy.__enter__'s yyrc8|jjyr)rreleaserexc_type exc_value tracebacks r__exit__zAcquireReturnProxy.__exit__*s rN)r BaseFileLockreturnNone)r(r'r#ztype[BaseException] | Noner$zBaseException | Noner%zTracebackType | Noner(r))__name__ __module__ __qualname____doc__rrr&rrrr!s:N,((   rrcVeZdZUdZded<ded<ded<ded <d Zd ed <d Zded<y )FileLockContextzBA dataclass which holds the context for a ``BaseFileLock`` object.str lock_filefloattimeoutintmodeboolblockingNz int | None lock_file_fdr lock_counter)r+r,r-r.__annotations__r:r;r/rrr1r13s9L NN IN $L*#L#rr1ceZdZdZy)ThreadLocalFileContextz8A thread local version of the ``FileLockContext`` class.N)r+r,r-r.r/rrr>r>MsBrr>cNeZdZ dddd dfdZxZS) FileLockMetaTFr9 is_singletonc |r|jjt|}|r||jf||jf||j f||j fd} | jD cic]\} \} } | | k7r| | | f} } } } | s td|Sd}|dz }| jD]\}\} } |d|d| d| dz }t||||||d |}tj|jj}|jDcic] \}}||vs ||}}}t|<|fi|}|r||jt|<td|Scc} } } wcc}}w) N) thread_localr5r7r9r'zGSingleton lock instances cannot be initialized with differing argumentsz Non-matching arguments: z z (existing lock has z but z was passed))r5r7rDr9rB) _instancesgetr2is_thread_localr5r7r9itemsr ValueErrorinspect signaturer parameterssuper__call__)clsr3r5r7rDr9rBkwargsinstanceparams_to_checkname passed_param set_paramnon_matching_paramsmsg param_name all_paramspresent_paramskeyvalue init_params __class__s rrNzFileLockMeta.__call__Rs ~~))#i.9H%183K3K3M$N ')9)9:!8==1!)8+<+< = #4D4D4F`jc5#Q_J_sEz` `7#I== -5CNN3y> *NH--I':as9E/$ E61E6iT)r3str | os.PathLike[str]r5r4r7r6rDr8r9r8rBr8rPr r(r')r+r,r-rN __classcell__r^s@rr@r@Qss! 9."9.)9.9. 9.  9.9.9.9. 9.9.rr@ceZdZUdZded<dfd Z dddd ddZdd Zedd Z ed d Z ed!d Z e jd"d Z eddZ e jd#dZ ed$dZed%dZed%dZeddZed$dZ d&ddd d'dZd(d)dZd*dZ d+dZd%dZxZS),r'z+Abstract base class for a file lock object.z&WeakValueDictionary[str, BaseFileLock]rEc Bt|di|t|_y)z'Setup unique state for lock subclasses.Nr/)rM__init_subclass__r rE)rOrPr^s rrfzBaseFileLock.__init_subclass__s !+F+,.rTFrAc||_||_tj||||d}|rtnt di||_y)a Create a new lock object. :param lock_file: path to the file :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. :param mode: file permissions for the lockfile :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. :param blocking: whether the lock should be blocking or not :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. )r3r5r7r9Nr/)_is_thread_local _is_singletonosfspathr>r1_context)rr3r5r7rDr9rBrPs rrzBaseFileLock.__init__sM4!-) 9- "  +fL*@Ve)pio)p rc|jS)z>:return: a flag indicating if this lock is thread local or not)rhrs rrGzBaseFileLock.is_thread_locals$$$rc|jS)z;:return: a flag indicating if this lock is singleton or not)rirs rrBzBaseFileLock.is_singletons!!!rc.|jjS)z:return: path to the lock file)rlr3rs rr3zBaseFileLock.lock_files}}&&&rc.|jjS)za :return: the default timeout value, in seconds .. versionadded:: 2.0.0 )rlr5rs rr5zBaseFileLock.timeouts}}$$$rc8t||j_y)ze Change the default timeout value. :param value: the new value, in seconds N)r4rlr5rr\s rr5zBaseFileLock.timeouts!&e  rc.|jjS)z/:return: whether the locking is blocking or notrlr9rs rr9zBaseFileLock.blockings}}%%%rc&||j_y)zb Change the default blocking value. :param value: the new value as bool Nrtrrs rr9zBaseFileLock.blockings"' rc.|jjS)z.:return: the file permissions for the lockfile)rlr7rs rr7zBaseFileLock.modes}}!!!rct)zjIf the file lock could be acquired, self._context.lock_file_fd holds the file descriptor of the lock file.NotImplementedErrorrs r_acquirezBaseFileLock._acquire "!rct)z>Releases the lock and sets self._context.lock_file_fd to None.rxrs r_releasezBaseFileLock._releaser{rc2|jjduS)z :return: A boolean indicating if the lock file is holding the lock currently. .. versionchanged:: 2.0.0 This was previously a method and is now a property. N)rlr:rs r is_lockedzBaseFileLock.is_lockeds}}))55rc.|jjS)zP:return: The number of times this lock has been acquired (but not yet released).)rlr;rs rr;zBaseFileLock.lock_counter s}})))rN)poll_intervallr9c||jj}||jj}| d}tj|t d|}|jxj dz c_t|}|j}tj} |js'tjd|||j|jrtjd||n|dur"tjd||t|d |cxkrtj|z kr%nn"tjd ||t|d }tj||||tj | t'| S#t"$r4t%d |jj dz |j_wxYw) a_ Try to acquire the file lock. :param timeout: maximum wait time for acquiring the lock, ``None`` means use the default :attr:`~timeout` is and if ``timeout < 0``, there is no timeout and this method will block until the lock could be acquired :param poll_interval: interval of trying to acquire the lock file :param poll_intervall: deprecated, kept for backwards compatibility, use ``poll_interval`` instead :param blocking: defaults to True. If False, function will return immediately if it cannot obtain a lock on the first attempt. Otherwise, this method will block until the timeout expires or the lock is acquired. :raises Timeout: if fails to acquire lock within the timeout period :return: a context object that will unlock the file when the context is exited .. code-block:: python # You can use this method in the context manager (recommended) with lock.acquire(): pass # Or use an equivalent try-finally construct: lock.acquire() try: pass finally: lock.release() .. versionchanged:: 2.0.0 This method returns now a *proxy* object instead of *self*, so that it can be used in a with statement without side effects. z+use poll_interval instead of poll_intervall) stacklevelr z#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 ...r)rlr5r9warningswarnDeprecationWarningr;idr3time perf_counterr_LOGGERdebugrzr sleep BaseExceptionmaxr) rr5 poll_intervalrr9rWlock_id lock_filename start_times racquirezBaseFileLock.acquiresP ?mm++G  }}--H  %?C MM#1a @*M ""a'"T( &&(  ~~MM"GR_`MMO>>MM":G]Su$MM"OQXZgh!-00B$"3"3"5 "BBMM"FQ^_!-00J c7M=I =) "t,, ),Q 0J0JQ0N)ODMM &  s C3F=Gc`|jr|jxjdzc_|jjdk(s|rgt||j}}t j d|||jd|j_t j d||yyy)a+ Releases the file lock. Please note, that the lock is only completely released, if the lock counter is 0. Also note, that the lock file itself is not automatically deleted. :param force: If true, the lock counter is ignored and the lock is released in every case/ r rz#Attempting to release lock %s on %szLock %s released on %sN)rrlr;rr3rrr})rforcerrs rr!zBaseFileLock.release^s >> MM & &! + &}}))Q.%)+D4>> CWm\ -. * 6O 38 rc&|j|S)zF Acquire the lock. :return: the lock object )rrs rrzBaseFileLock.__enter__qs  rc$|jy)z Release the lock. :param exc_type: the exception type if raised :param exc_value: the exception value if raised :param traceback: the exception traceback if raised Nr!r"s rr&zBaseFileLock.__exit__{s  rc(|jdy)z'Called when the lock object is deleted.T)rNrrs r__del__zBaseFileLock.__del__s 4  r)rPzdict[str, Any]r(r)r_)r3rar5r4r7r6rDr8r9r8rBr8r(r))r(r8)r(r2)r(r4)r\z float | strr(r))r\r8r(r))r(r6)r(r))Ng?) r5 float | Nonerr4rrr9z bool | Noner(r)F)rr8r(r))r(rr*)r+r,r-r.r<rfrrGpropertyrBr3r5setterr9r7rrzr}rr;rr!rr&rrbrcs@rr'r's566/! %q"%q)%q%q %q  %q%q%q %qN%""''%% ^^--&&__''"""""" 6 6** !%#M- (, $ M-M-M- % M-  M- M-^P&,((    !rr') metaclass)& __future__r contextlibrJloggingrjrrabcrr dataclassesr threadingrtypingrr r weakrefr _errorr systypesr version_infortyping_extensions getLoggerrrr1r>r@ContextDecoratorr'__all__r/rrrs" '!++'# 7"* '  J ' $  2C_eC:.7:.z!:..,!F r