Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
_soft.cpython-313.pyc67 linesDownload Raw Back to __pycache__
1�

2�j����SSKJr SSKrSSKrSSKrSSKrSSKJr SSKJ	r	J3r4JrJr SSK
Jr SSKJr SSKJrJr S	rS5rSrSr"S
S\5rS/rg)�)�annotationsN)�suppress)�EACCES�EEXIST�EPERM�ESRCH)�Path�)�BaseFileLock)�ensure_directory_exists�raise_on_not_writable_filei�Wig@c��\rSrSrSrSSjrSSjrSSjr\SSj5r	\SSj5r6\SSj5r\SS	j5r
\SS7j5rSSjrSSjrSS
jrSrg)�SoftFileLock�a�8Portable file lock based on file existence.9 10Unlike :class:`UnixFileLock <filelock.UnixFileLock>` and :class:`WindowsFileLock <filelock.WindowsFileLock>`, this11lock does not use OS-level locking primitives. Instead, it creates the lock file with ``O_CREAT | O_EXCL`` and12treats its existence as the lock indicator. This makes it work on any filesystem but leaves stale lock files behind13if the process crashes without releasing the lock.14 15To mitigate stale locks, the lock file contains the PID and hostname of the holding process. On contention, if the16holder is on the same host and its PID no longer exists, the stale lock is broken automatically.17 18c�x�[UR5 [UR5 [R[R19-[R-[R-n[[SS5=nbX-n[R"URXR55nURU5 X0Rl
g![aWnUR[ :Xd)UR[":Xa[$R&S:XdeUR)5 SnAgSnAff=f)N�20O_NOFOLLOW�win32)r
�	lock_filer�os�O_WRONLY�O_CREAT�O_EXCL�O_TRUNC�getattr�open�21_open_mode�_write_lock_info�_context�lock_file_fd�OSError�errnorr�sys�platform�_try_break_stale_lock)�self�flags�22o_nofollow�file_handler�	exceptions     �@D:\code\apps\devtools\python\Lib\site-packages\filelock/_soft.py�_acquire�SoftFileLock._acquire"s���"�4�>�>�2�����/��K�K��j�j�
��i�i�
��j�j�
�	�"�"�l�D�9�9�J�F���E�23	6��7�7�4�>�>�5�/�/�:K�L�L�
�!�!�,�/�)5�M�M�&���	)����6�)�i�o�o��.G�C�L�L�\c�Lc���&�&�(�(��	)�s�/C�24D9�"A
D4�4D9c�0�[[[5 [UR5nUR5nUR
SS9nUR5R5n[U5S;aD[R"5UR-25[:�aUR5 SSS5 gUSUSpe[U5S:XaUSOSnU[R"5:wa26SSS5 g[!U5nUR#U5(aP[$R&S:Xa2Ub/[!U5n	UR)U5n27U28bX�:waOSSS5 gSSS5 gUR5 SSS5 g!,(df   g=f)	N�utf-8��encoding>��rr29r3r2r)rr!�30ValueErrorr	r�stat�	read_text�strip�31splitlines�len�time�st_mtime�_MALFORMED_LOCK_AGE_THRESHOLD�_evict_lock_file�socket�gethostname�int�_is_process_aliver#r$�_get_process_creation_time)r&�	lock_path�stat_result�content�lines�pid_str�hostname�creation_time_str�pid�stored�actuals           r+r%�"SoftFileLock._try_break_stale_lock9sV��
�g�z�
*��T�^�^�,�I�#�.�.�*�K��)�)�7�)�;�G��M�M�O�.�.�0�E��5�z��'��9�9�;��!5�!5�5�9V�V��)�)�+��+�
*�!&�a��%��(�X�,/��J�!�O��a�����6�-�-�/�/��+�
*�"�g�,�C��%�%�c�*�*��<�<�7�*�/@�/L� �!2�3�F�!�<�<�S�A�F��)�f�.>���5+�
*�8�9+�
*�<
�!�!�#�=+�
*�
*�s%�BF�;9F�=AF�$F�.F�32Fc���URS[R"53n[UR5R	U5 [U5R5 g)Nz.break.)rr�getpidr	�rename�unlink)r&�33break_paths  r+r=�SoftFileLock._evict_lock_fileZsE�����'�w�r�y�y�{�m�<�34��T�^�^��#�#�J�/��Z����!�c��[RS:XaaSSKnURRnUR[SU5nU(aURU5 gUR5[:g$[R"US5 g![a8nUR[:XaSnAgUR[:XaSnAgeSnAff=f)NrrTF)r#r$�ctypes�windll�kernel32�OpenProcess�_WIN_SYNCHRONIZE�CloseHandle�GetLastError�_WIN_ERROR_INVALID_PARAMETERr�killr!r"rr)rJrVrX�handle�excs     r+rA�SoftFileLock._is_process_alive_s����<�<�7�"���}�}�-�-�H��)�)�*:�A�s�C�F���$�$�V�,���(�(�*�.J�J�J�	��G�G�C��O���
�	��y�y�E�!���y�y�E�!����	�s$�7B�35C�C�2C�C�Cc	��[RS:wagSSKnSSKJn URR36nUR
[SU5nU(dgUR5nUR5nUR5nUR5nURUURU5URU5URU5URU55(dURU5 gURU5 URS-UR-$!URU5 f=f)zRReturn the process creation FILETIME as an integer on Windows, ``None`` otherwise.rNr)�wintypes� )r#r$rVrcrWrXrY�&_WIN_PROCESS_QUERY_LIMITED_INFORMATION�FILETIME�GetProcessTimes�byrefr[�dwHighDateTime�
dwLowDateTime)	rJrVrcrXr_�creation�	exit_time�kernel_time�	user_times	         r+rB�'SoftFileLock._get_process_creation_timets���<�<�7�"���#��=�=�)�)���%�%�&L�a�QT�U����	)��(�(�*�H� �)�)�+�I�"�+�+�-�K� �)�)�+�I��+�+�����X�&����Y�'����[�)����Y�'����� � ��(��
� � ��(��'�'�2�-��1G�1G�G�G��
� � ��(�s
�BD-�-Ec��[[5 [R"5S[R37"5S3n[RS:Xa2[R[R"55=nbXS3-
n[R"XR55 SSS5 g!,(df   g=f)N�38r)rr!rrOr>r?r#r$rrB�write�encode)�fd�info�cts   r+r�SoftFileLock._write_lock_info�s���
�g�
��i�i�k�]�"�V�%7�%7�%9�$:�"�=�D��|�|�w�&�,�2Y�2Y�Z\�Zc�Zc�Ze�2f�,f�B�+s��$�b�	�!���H�H�R����'�	�
�
�s�BB2�239Cc���[UR5RSS9nUR5R	5nU(a[US5$g![[4a gf=f)z�40The PID of the process holding this lock, read from the lock file.41 42:returns: the PID as an integer, or ``None`` if the lock file does not exist or cannot be parsed43 44r/r0rN)r	rr6r7r8r@r!r4)r&rErFs   r+rJ�SoftFileLock.pid�sn��	��4�>�>�*�4�4�g�4�F�G��M�M�O�.�.�0�E���5��8�}�$������$�	���	�s�AA�A,�+A,c�F�UR[R"5:H$)z�45Whether this lock is held by the current process.46 47:returns: ``True`` if the lock file exists and contains the current process's PID48 49)rJrrO�r&s r+�is_lock_held_by_us�SoftFileLock.is_lock_held_by_us�s���x�x�2�9�9�;�&�&rTc��[[5 [UR5R	5 SSS5 g!,(df   g=f)zNForcibly break the lock by removing the lock file, regardless of who holds it.N)rr!r	rrQr{s r+�50break_lock�SoftFileLock.break_lock�s+��
�g�
����� �'�'�)��
�
�s	�$=�51Ac��URRce[R"URR5 SURl[R52S:XaUR
5 g[[5 [UR5R5 SSS5 g!,(df   g=f)Nr)rr r�closer#r$�_windows_unlink_with_retryrr!r	rrQr{s r+�_release�SoftFileLock._release�s{���}�}�)�)�5�5�5�53������+�+�,�%)��
�
�"��<�<�7�"��+�+�-��'�"��T�^�^�$�+�+�-�#�"�"�s�	$B6�654Cc�:�SnSn[U5H'n[UR5R5  g g![aTnUR55[[1;aSnA gX1S-56:a![R"U5 US-nSnAMSnAM�SnAff=f)N�57g����MbP?r58r2)59�ranger	rrQr!r"rrr:�sleep)r&�max_retries�retry_delay�attemptr`s     r+r��'SoftFileLock._windows_unlink_with_retry�s��������[�)�G�	
��T�^�^�$�+�+�-��*���
%��9�9�V�U�O�3���1�_�,��J�J�{�+��1�$�K�-��
%�s�#<�60B�B�&#B�B�N)�return�None)rJr@r��bool)rJr@r��61int | None)rtr@r�r�)r�r�)r�r�)�__name__�62__module__�__qualname__�__firstlineno__�__doc__r,r%r=�staticmethodrArBr�propertyrJr|rr�r��__static_attributes__r�rTr+rrs����6�.$�B"�63����(�H��H�8�(��(����� �'��'�*�64.�rTr)�65__future__rrr>r#r:�66contextlibrr"rrrr�pathlibr	�_apir�_utilrr
rZr]rer<r�__all__r�rTr+�<module>r�sY��"�	�
�67���.�.���F���!��)/�&� #��}�<�}�B��rT