Warning: session_start(): Session cannot be started after headers have already been sent in /home/tvrreohg/public_html/manga.php on line 13
3
ÝPfÊ ã @ st d Z ddlmZ ddlZddlZddlZddlmZmZm Z m
Z
mZmZ G dd„ deƒZ
dd „ Zd
d„ Zdd
„ ZdS )z8 Lockfile behaviour implemented via Unix PID files.
é )Úabsolute_importNé )ÚLockBaseÚ
AlreadyLockedÚ
LockFailedÚ NotLockedÚ NotMyLockÚLockTimeoutc @ sL e Zd ZdZddd„Zdd„ Zdd „ Zd
d„ Zddd
„Zdd„ Z dd„ Z
dS )ÚPIDLockFileaA Lockfile implemented as a Unix PID file.
The lock file is a normal file named by the attribute `path`.
A lock's PID file contains a single line of text, containing
the process ID (PID) of the process that acquired the lock.
>>> lock = PIDLockFile('somefile')
>>> lock = PIDLockFile('somefile')
FNc C s t j| |d|ƒ | j| _d S )NF)r Ú__init__ÚpathZunique_name)Úselfr ZthreadedÚtimeout© r ú!/usr/lib/python3.6/pidlockfile.pyr $ s zPIDLockFile.__init__c C s
t | jƒS )z- Get the PID from the lock file.
)Úread_pid_from_pidfiler )r
r r r Úread_pid* s zPIDLockFile.read_pidc C s t jj| jƒS )zv Test if the lock is currently held.
The lock is held if the PID file for this lock exists.
)Úosr Úexists)r
r r r Ú is_locked/ s zPIDLockFile.is_lockedc C s | j ƒ otjƒ | jƒ kS )z¡ Test if the lock is held by the current process.
Returns ``True`` if the current process ID matches the
number stored in the PID file.
)r r Úgetpidr )r
r r r Úi_am_locking7 s zPIDLockFile.i_am_lockingc C sâ |dk r|n| j }tjƒ }|dk r2|dkr2||7 }xªyt| jƒ W n’ tk
rÔ } zv|jtjkr¶tjƒ |krš|dk rŒ|dkrŒtd| j ƒ‚ntd| j ƒ‚tj |dk r®|d p°dƒ nt
d| j ƒ‚W Y dd}~X q4X dS q4W dS )z† Acquire the lock.
Creates the PID file for this lock, or raises an error if
the lock could not be acquired.
Nr z&Timeout waiting to acquire lock for %sz%s is already lockedé
gš™™™™™¹?zfailed to create %s)r ÚtimeÚwrite_pid_to_pidfiler ÚOSErrorÚerrnoZEEXISTr r Zsleepr )r
r Zend_timeÚexcr r r Úacquire? s$
zPIDLockFile.acquirec C s: | j ƒ std| j ƒ‚| jƒ s,td| j ƒ‚t| jƒ dS )z¥ Release the lock.
Removes the PID file to release the lock, or raises an
error if the current process does not hold the lock.
z%s is not lockedz%s is locked, but not by meN)r r r r r Úremove_existing_pidfile)r
r r r Úrelease_ s
zPIDLockFile.releasec C s t | jƒ dS )z‚ Break an existing lock.
Removes the PID file if it already exists, otherwise does
nothing.
N)r r )r
r r r Ú
break_lockl s zPIDLockFile.break_lock)FN)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r r r r r r r! r r r r r
s
r
c C sb d}yt | dƒ}W n tk
r& Y n8X |jƒ jƒ }yt|ƒ}W n tk
rT Y nX |jƒ |S )zï Read the PID recorded in the named PID file.
Read and return the numeric PID recorded as text in the named
PID file. If the PID file cannot be read, or if the content is
not a valid PID, return ``None``.
NÚr)ÚopenÚIOErrorÚreadlineÚstripÚintÚ
ValueErrorÚclose)Úpidfile_pathÚpidÚpidfileÚliner r r r v s r c C sR t jt jB t jB }d}t j| ||ƒ}t j|dƒ}t jƒ }|jd| ƒ |jƒ dS )u° Write the PID in the named PID file.
Get the numeric process ID (“PID�) of the current process
and write it to the named file as a line of text.
i¤ Úwz%s
N) r ÚO_CREATÚO_EXCLÚO_WRONLYr' Úfdopenr Úwriter- )r. Z
open_flagsZ open_modeZ
pidfile_fdr0 r/ r r r r ˜ s r c C sF yt j| ƒ W n2 tk
r@ } z|jtjkr.n‚ W Y dd}~X nX dS )zÏ Remove the named PID file if it exists.
Removing a PID file that doesn't already exist puts us in the
desired state, so we ignore the condition if the file does not
exist.
N)r Úremover r ÚENOENT)r. r r r r r ° s r )r% Z
__future__r r r r Ú r r r r r r r
r r r r r r r Ú
s ]"