Ϫf!TUdZddlmZddlZddlmZmZmZddl m Z ddl m Z m Z mZddlmZmZddlmZdd lmZGd d eZeeGd d ZeeGddZeZd ed<GddeZGddeZGddeZGddeZy)z PID file. ) annotationsN)getpidkillname) TracebackType)AnyOptionalType) Interface implementer)Logger)FilePathcPeZdZdZd dZd dZd dZd dZd dZ d dZ y)IPIDFilez5 Manages a file that remembers a process ID. cy)a+ Read the process ID stored in this PID file. @return: The contained process ID. @raise NoPIDFound: If this PID file does not exist. @raise EnvironmentError: If this PID file cannot be read. @raise ValueError: If this PID file's content is invalid. NrE/usr/lib/python3/dist-packages/twisted/application/runner/_pidfile.pyreadz IPIDFile.readrcy)z Store the PID of the current process in this PID file. @raise EnvironmentError: If this PID file cannot be written. NrrrrwriteRunningPIDzIPIDFile.writeRunningPID%rrcy)zm Remove this PID file. @raise EnvironmentError: If this PID file cannot be removed. NrrrrremovezIPIDFile.remove,rrcy)a Determine whether there is a running process corresponding to the PID in this PID file. @return: True if this PID file contains a PID and a process with that PID is currently running; false otherwise. @raise EnvironmentError: If this PID file cannot be read. @raise InvalidPIDFileError: If this PID file's content is invalid. @raise StalePIDFileError: If this PID file's content refers to a PID for which there is no corresponding running process. Nrrrr isRunningzIPIDFile.isRunning3rrcy)z Enter a context using this PIDFile. Writes the PID file with the PID of the running process. @raise AlreadyRunningError: A process corresponding to the PID in this PID file is already running. Nrrrr __enter__zIPIDFile.__enter__Arrcy)zS Exit a context using this PIDFile. Removes the PID file. Nr)excTypeexcValue tracebacks r__exit__zIPIDFile.__exit__KrrNreturnintr%Noner%bool)r%z 'IPIDFile')r Optional[Type[BaseException]]r!Optional[BaseException]r"Optional[TracebackType]r%zOptional[bool]) __name__ __module__ __qualname____doc__rrrrrr#rrrrrsI         .  )  +     rrceZdZdZeZed dZddZddZ ddZ ddZ ddZ ddZ edd Zdd Z dd Zy )PIDFilez Concrete implementation of L{IPIDFile}. This implementation is presently not supported on non-POSIX platforms. Specifically, calling L{PIDFile.isRunning} will raise L{NotImplementedError}. c:t|djS)z Format a PID file's content. @param pid: A process ID. @return: Formatted PID file contents.  )r&encodepids r_formatzPIDFile._formatcsc(2%%''rc||_y)zD @param filePath: The path to the PID file on disk. N)filePath)selfr;s r__init__zPIDFile.__init__ns ! rc8d} |jj5}|D]}nddd t |S#1swYxYw#t$r.}|jtjk(r t dd}~wwxYw#t$rtd|wxYw)NrPID file does not existz#non-integer PID value in PID file: ) r;openOSErrorerrnoENOENT NoPIDFoundr& ValueErrorInvalidPIDFileError)r< pidStringfhes rrz PIDFile.readts  ##% !#I  y> !   ww%,,& !:;;   %5i]C  s6A ;A BAA A>)A99A>BcZ|jj|j|y)z Store a PID in this PID file. @param pid: A PID to store. @raise EnvironmentError: If this PID file cannot be written. r7N)r; setContentr9r<r8s r_writezPIDFile._writes!   #!67rc6|jtyN)rMrr<s rrzPIDFile.writeRunningPIDs FHrc8|jjyrO)r;rrPs rrzPIDFile.removes rc |j}tdk(r|j|St dt#t$rYywxYw)NFposixz isRunning is not implemented on )rrD SYSTEM_NAME_pidIsRunningPOSIXNotImplementedErrorrLs rrzPIDFile.isRunningsT ))+C ' !**3/ /%(H &VW W   s> A  A c t|dy#t$rP}|jtjk(r t d|jtj k(rYd}~yd}~wwxYw)a1 POSIX implementation for running process check. Determine whether there is a running process corresponding to the given PID. @param pid: The PID to check. @return: True if the given PID is currently running; false otherwise. @raise EnvironmentError: If this PID file cannot be read. @raise InvalidPIDFileError: If this PID file's content is invalid. @raise StalePIDFileError: If this PID file's content refers to a PID for which there is no corresponding running process. rTz'PID file refers to non-existing processN)rrArBESRCHStalePIDFileErrorEPERM)r8rIs rrUzPIDFile._pidIsRunningPOSIXsY"  aL ww%++%'(QRREKK'  s  A(AA#"A##A(c |jr t |j |S#t$r|jj dY8wxYw)Nz&Replacing stale PID file: {log_source})rAlreadyRunningErrorrY_loginforrPs rrzPIDFile.__enter__sW E~~)++   ! E IINNC D Es/$AAc$|jyrO)rr<r r!r"s rr#zPIDFile.__exit__s rN)r8r&r%bytes)r;z FilePath[Any]r%r(r$r8r&r%r(r'r))r8r&r%r*)r%z 'PIDFile'r r+r!r,r"r-r%r()r.r/r0r1r r] staticmethodr9r=rrMrrrrUrr#rrrr3r3Ws 8D((! $8 X8.*+   rr3c`eZdZdZd dZd dZd dZd dZd dZddZ ddZ dd Z y ) NonePIDFilez PID file implementation that does nothing. This is meant to be used as a "active None" object in place of a PID file when no PID file is desired. cyrOrrPs rr=zNonePIDFile.__init__s rctd)Nr?)rDrPs rrzNonePIDFile.reads233rc6ttjd)z Store a PID in this PID file. @param pid: A PID to store. @raise EnvironmentError: If this PID file cannot be written. @note: This implementation always raises an L{EnvironmentError}. zOperation not permitted)rArBrZrLs rrMzNonePIDFile._writesekk#<==rc&|jdy)Nr)rMrPs rrzNonePIDFile.writeRunningPIDs  Arc6ttjd)NzNo such file or directory)rArBrCrPs rrzNonePIDFile.removesell$?@@rcy)NFrrPs rrzNonePIDFile.isRunningsrc|SrOrrPs rrzNonePIDFile.__enter__s rcyrOrr`s rr#zNonePIDFile.__exit__s rNr'r$rbr))r%z 'NonePIDFile'rc) r.r/r0r1r=rrMrrrrr#rrrrfrfsV 4 >A.*+   rrf nonePIDFileceZdZdZy)r\z% Process is already running. Nr.r/r0r1rrrr\r\rr\ceZdZdZy)rFz( PID file contents are invalid. NrqrrrrFrF rrrrFceZdZdZy)rYz[ PID file contents are valid, but there is no process with the referenced PID. NrqrrrrYrYsrrYceZdZdZy)rDz# No PID found in PID file. NrqrrrrDrDrrrrD) r1 __future__rrBosrrrrTtypesrtypingrr r zope.interfacer r twisted.loggerr twisted.python.filepathrrr3rfro__annotations__ Exceptionr\rFrYrDrrrrs # 00&&1!,? y? D Xvvvr X,,,^$ X%) )  r