o
    úùÎhø  ã                   @   s*   d dl Z d dlZd dlZG dd„ dƒZdS )é    Nc                   @   s2   e Zd ZdZddd„Zdd„ Zdd	„ Zd
d„ ZdS )Ú	FileBatonz0A primitive, file-based synchronization utility.çš™™™™™¹?Nc                 C   s   || _ || _d| _|| _dS )an  
        Create a new :class:`FileBaton`.

        Args:
            lock_file_path: The path to the file used for locking.
            wait_seconds: The seconds to periodically sleep (spin) when
                calling ``wait()``.
            warn_after_seconds: The seconds to wait before showing
                lock file path to warn existing lock file.
        N)Úlock_file_pathÚwait_secondsÚfdÚwarn_after_seconds)Úselfr   r   r   © r	   ú\/home/www/facesmatcher.com/frenv_anti/lib/python3.10/site-packages/torch/utils/file_baton.pyÚ__init__
   s   
zFileBaton.__init__c                 C   s4   zt  | jt jt jB ¡| _W dS  ty   Y dS w )z–
        Try to atomically create a file under exclusive access.

        Returns:
            True if the file could be created, else False.
        TF)ÚosÚopenr   ÚO_CREATÚO_EXCLr   ÚFileExistsError©r   r	   r	   r
   Útry_acquire   s   ÿzFileBaton.try_acquirec                 C   s|   d}t   ¡ }tj | j¡r<t  | j¡ | jdur3t   ¡ | | jkr3|s3t 	d| j› d| j› d¡ d}tj | j¡sdS dS )zÆ
        Periodically sleeps for a certain amount until the baton is released.

        The amount of time slept depends on the ``wait_seconds`` parameter
        passed to the constructor.
        FNzWaited on lock file "z" for z	 seconds.T)
Útimer   ÚpathÚexistsr   Úsleepr   r   ÚwarningsÚwarn)r   Z
has_warnedÚ
start_timer	   r	   r
   Úwait'   s   

ÿùzFileBaton.waitc                 C   s&   | j durt | j ¡ t | j¡ dS )z'Release the baton and removes its file.N)r   r   ÚcloseÚremover   r   r	   r	   r
   Úrelease:   s   
zFileBaton.release)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r	   r	   r	   r
   r      s    
r   )r   r   r   r   r	   r	   r	   r
   Ú<module>   s   