← Back
Editing: _pidfile.cpython-38.pyc
U W[S � @ s� d Z ddlZddlmZmZmZ ddlmZm Z ddl mZ G dd� de�Ze e�G dd � d e ��Ze e�G d d� de ��Ze� ZG dd � d e�ZG dd� de�ZG dd� de�ZG dd� de�ZdS )z PID file. � N)�getpid�kill�name)� Interface�implementer)�Loggerc @ s@ e Zd ZdZdd� Zdd� Zdd� Zdd � Zd d� Zdd � Z dS )�IPIDFilez5 Manages a file that remembers a process ID. c C s dS )aB Read the process ID stored in this PID file. @return: The contained process ID. @rtype: L{int} @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. N� r r r �E/usr/lib/python3/dist-packages/twisted/application/runner/_pidfile.py�read s z IPIDFile.readc C s dS )z� Store the PID of the current process in this PID file. @raise EnvironmentError: If this PID file cannot be written. Nr r r r r �writeRunningPID$ s zIPIDFile.writeRunningPIDc C s dS )zm Remove this PID file. @raise EnvironmentError: If this PID file cannot be removed. Nr r r r r �remove, s zIPIDFile.removec C s dS )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. @rtype: L{bool} @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. Nr r r r r � isRunning4 s zIPIDFile.isRunningc C s dS )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. Nr r r r r � __enter__D s zIPIDFile.__enter__c C s dS )zS Exit a context using this PIDFile. Removes the PID file. Nr )�excType�excValue� tracebackr r r �__exit__O s zIPIDFile.__exit__N) �__name__� __module__�__qualname__�__doc__r r r r r r r r r r r s r c @ sn e Zd ZdZe� Zedd� �Zdd� Zdd� Z dd � Z d d� Zdd � Zdd� Z edd� �Zdd� Zdd� ZdS )�PIDFilez� Concrete implementation of L{IPIDFile} based on C{IFilePath}. This implementation is presently not supported on non-POSIX platforms. Specifically, calling L{PIDFile.isRunning} will raise L{NotImplementedError}. c C s d� t| ���d�S )z� Format a PID file's content. @param pid: A process ID. @type pid: int @return: Formatted PID file contents. @rtype: L{bytes} z{} zutf-8)�format�int�encode��pidr r r �_formate s zPIDFile._formatc C s || _ dS )zi @param filePath: The path to the PID file on disk. @type filePath: L{IFilePath} N)�filePath)�selfr r r r �__init__s s zPIDFile.__init__c C s� d}z(| j �� �}|D ]} q qW 5 Q R X W n8 tk rd } z|jtjkrRtd��� W 5 d }~X Y nX z t|�W S tk r� td� |���Y nX d S )N� �PID file does not existz'non-integer PID value in PID file: {!r}) r �open�OSError�errno�ENOENT� NoPIDFoundr � ValueError�InvalidPIDFileErrorr )r Z pidStringZfh�er r r r { s �zPIDFile.readc C s | j �| j|d�� dS )z� Store a PID in this PID file. @param pid: A PID to store. @type pid: L{int} @raise EnvironmentError: If this PID file cannot be written. r N)r Z setContentr �r r r r r �_write� s zPIDFile._writec C s | � t� � d S �N)r- r �r r r r r � s zPIDFile.writeRunningPIDc C s | j �� d S r. )r r r/ r r r r � s zPIDFile.removec C sH z| � � }W n tk r" Y dS X tdkr6| �|�S td�t���d S )NF�posixz"isRunning is not implemented on {})r r( �SYSTEM_NAME�_pidIsRunningPOSIX�NotImplementedErrorr r, r r r r � s �zPIDFile.isRunningc C sh zt | d� W nP tk r^ } z2|jtjkr6td��n|jtjkrLW Y � dS � W 5 d}~X Y nX dS dS )a" POSIX implementation for running process check. Determine whether there is a running process corresponding to the given PID. @return: True if the given PID is currently running; false otherwise. @rtype: L{bool} @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. r z'PID file refers to non-existing processTN)r r% r&