o
    U)i                     @   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   b/home/app/PaddleOCR-VL-test/.venv_paddleocr/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   