a
    .=ict  ã                   @   s"   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.çš™™™™™¹?c                 C   s   || _ || _d| _dS )zñ
        Creates a new :class:`FileBaton`.

        Args:
            lock_file_path: The path to the file used for locking.
            wait_seconds: The seconds to periorically sleep (spin) when
                calling ``wait()``.
        N)Úlock_file_pathÚwait_secondsÚfd)Úselfr   r   © r   úg/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/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˜
        Tries 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   s    t j | j¡rt | j¡ 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.
        N)r   ÚpathÚexistsr   ÚtimeÚsleepr   r   r   r   r	   Úwait"   s    zFileBaton.waitc                 C   s&   | j durt | j ¡ t | j¡ dS )z(Releases the baton and removes its file.N)r   r   ÚcloseÚremover   r   r   r   r	   Úrelease,   s    
zFileBaton.releaseN)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   r   r   r   r   r   r	   r      s
   

r   )r   r   r   r   r   r   r	   Ú<module>   s   