a
    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	   R/var/www/html/assistant/venv/lib/python3.9/site-packages/torch/utils/file_baton.py__init__
   s    zFileBaton.__init__c                 C   s8   zt | jt jt jB | _W dS  ty2   Y dS 0 dS )z
        Try to atomically create a file under exclusive access.

        Returns:
            True if the file could be created, else False.
        TFN)osopenr   O_CREATO_EXCLr   FileExistsErrorr   r	   r	   r
   try_acquire   s
    zFileBaton.try_acquirec                 C   sl   d}t   }tj| jrht | j | jdurt   | | jkr|st	d| j d| j d d}q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   