U
    Mh                     @   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   H/var/www/html/venv/lib/python3.8/site-packages/torch/utils/file_baton.py__init__	   s    	zFileBaton.__init__c                 C   s:   zt | jt jt jB | _W dS  tk
r4   Y dS X 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   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k	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   