
    sg                     (    d dl Z d dlZ G d d      Zy)    Nc                   *    e Zd ZdZddZd Zd Zd Zy)	FileBatonz0A primitive, file-based synchronization utility.c                 .    || _         || _        d| _        y)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   s      I/var/www/html/venv/lib/python3.12/site-packages/torch/utils/file_baton.py__init__zFileBaton.__init__	   s     -(    c                     	 t        j                  | j                  t         j                  t         j                  z        | _        y# t        $ r Y yw xY 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	   s    r
   try_acquirezFileBaton.try_acquire   sA    	ggd112::		3IJDG 		s   AA 	AAc                     t         j                  j                  | j                        rJt	        j
                  | j                         t         j                  j                  | j                        rIyy)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   s    r
   waitzFileBaton.wait#   sD     ggnnT001JJt(() ggnnT001r   c                     | j                   t        j                  | j                          t        j                  | j                         y)z'Release the baton and removes its file.N)r   r   closeremover   r   s    r
   releasezFileBaton.release-   s.    77HHTWW
		$%%&r   N)g?)__name__
__module____qualname____doc__r   r   r   r    r   r
   r   r      s    :*'r   r   )r   r   r   r#   r   r
   <module>r$      s    	 ,' ,'r   