o
    ðÇh‹  ã                   @   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ð
        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()``.
        N)Úlock_file_pathÚwait_secondsÚfd)Úselfr   r   © r   új/var/www/html/construction_image-detection-poc/venv/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   s0   t j | j¡rt | j¡ 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.
        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'Release 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   