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	   úD/var/www/auris/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   