
    AHj                         d Z ddlZddlZddlZddlZddlZ ej                  e      Z G d de	      Z
 G d de      Zy)zEA cross-process lock based on exclusive creation of a given file name    Nc                       e Zd ZdZy)	LockErrorz.It will be raised when unable to obtain a lockN)__name__
__module____qualname____doc__     P/root/tools/cai/cai_env/lib/python3.12/site-packages/msal_extensions/filelock.pyr   r      s    8r
   r   c                   (    e Zd ZdZd Zd Zd Zd Zy)CrossPlatLockz5This implementation relies only on ``open(..., 'x')``c                     || _         y )N)	_lockpath)selflockfile_paths     r   __init__zCrossPlatLock.__init__   s	    &r
   c                     | j                  dj                  t        j                         t        j
                  d         j                  d             | S )Nz{} {}r   zutf-8)_create_lock_fileformatosgetpidsysargvencode)r   s    r   	__enter__zCrossPlatLock.__enter__   sA    w~~IIKHHQK  fWo	 r
   c                    d}d}t        t        dt        j                        } |       |z   }| |       kD  r2	 t        | j                  d      5 }|j	                  |       d d d        y t        dj                  || j                              # 1 sw Y   y xY w# t
        $ r t        d      t        $ rA t        j                  dt        j                         |       t        j                  |       Y nw xY w| |       kD  rΌ)N   g      ?	monotonicxbz1Python 2 does not support atomic creation of filez?Process %d found existing lock file, will retry after %f secondznUnable to obtain lock, despite trying for {} second(s). You may want to manually remove the stale lock file {})getattrtimeopenr   write
ValueErrorr   FileExistsErrorloggerdebugr   r   sleepr   )r   contenttimeoutcheck_intervalcurrent_timetimeout_end	lock_files          r   r   zCrossPlatLock._create_lock_file   s    t[$))<"nw.LN*
+$..$/ -9OOG,- EEKVF 	- U STT" +UIIK1 

>*	+ LN*s0   B B!B BB B AC87C8c                     	 t        j                  | j                         y # t        $ rM}|j                  t        j
                  t        j                  fv rt        j                  d       n Y d }~y d }~ww xY w)NzUnable to remove lock file)	r   remover   OSErrorerrnoENOENTEACCESr&   r'   )r   argsexs      r   __exit__zCrossPlatLock.__exit__4   sW    	IIdnn% 	xxELL%,,77 9: ;		s   " 	A8AA33A8N)r   r   r   r   r   r   r   r7   r	   r
   r   r   r      s    ?'0	r
   r   )r   r   r   r2   r!   logging	getLoggerr   r&   RuntimeErrorr   objectr   r	   r
   r   <module>r<      sC    K 	 
    
		8	$9 9-F -r
   