AlkantarClanX12

Your IP : 18.118.255.51


Current Path : /proc/self/root/lib/python3.6/site-packages/rhn/__pycache__/
Upload File :
Current File : //proc/self/root/lib/python3.6/site-packages/rhn/__pycache__/rhnLockfile.cpython-36.pyc

3

U��Zc
�@s~ddlZddlZddlZddlmZmZddlmZddlZGdd�de�Z	Gdd�d�Z
dd	�Zed
krzej
e�pvd�dS)�N)�EWOULDBLOCK�EEXIST)�bstrc@seZdZdZdS)�LockfileLockedExceptionz$thrown ONLY when pid file is locked.N)�__name__�
__module__�__qualname__�__doc__�r
r
�!/usr/lib/python3.6/rhnLockfile.pyrsrc@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
�Lockfilez�class that provides simple access to a PID-style lockfile.

    methods: __init__(lockfile), acquire(), and release()
    NOTE: currently acquires upon init
    The *.pid file will be acquired, or an LockfileLockedException is raised.
    NcCs�tjjtjjtjj|���|_||_|js4tj�|_tjj|j�}tjj	|�s�ytj
|�Wn8tk
r�tj
�d}t|d�r�|jtkr�n�YnXtj|jtjtjBtjB�|_|j�dS)zlcreate (if need be), and acquire lock on lockfile

        lockfile example: '/var/run/up2date.pid'
        ��errnoN)�os�path�abspath�
expanduser�
expandvars�lockfile�pid�getpid�dirname�exists�makedirs�OSError�sys�exc_info�hasattrrr�open�O_RDWR�O_CREAT�O_SYNC�f�acquire)�selfrrr�er
r
r�__init__$s"
zLockfile.__init__c
Cs�ytj|jtjtjB�WnDtk
r^tj�djt	krXt
d|jdtj�d��n�YnXtj|jtjd�t
j|jd�t
j|jtt|j�d��dS)z5acquire the lock; else raise LockfileLockedException.r
zcannot acquire lock on %s.N�r�
)�fcntl�flockr"ZLOCK_EXZLOCK_NB�IOErrorrrrrrrZF_SETFDr�	ftruncate�writer�strr)r$r
r
rr#EszLockfile.acquirecCs,tj|j�tj|jtj�tj|j�dS)N)r�unlinkrr)r*r"ZLOCK_UN�close)r$r
r
r�releaseVszLockfile.release)N)rrrr	r&r#r1r
r
r
rrs
!rcCszytd�}Wn6tk
rBtjjdtj�d�tjd
�Yn4Xtd�td�ddl}|j	d�|j
�td	�dS)z	test codez
./test.pidz%s
r
zlock acquired z...sleeping for 10 secondsrN�
zlock released ���)rrr�stderrr-r�exit�print�timeZsleepr1)�Lr7r
r
r�main]s
r9�__main__)rrr)rrrZrhn.i18nr�	Exceptionrrr9rr5r
r
r
r�<module>sB