%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/runner/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/runner/__pycache__/procmon.cpython-312.pyc

�

Ϫ�f�4��R�dZddlmZmZmZddlZddlZddlmZddl	m
Z
mZmZ
ddlmZddlmZddlmZej(d	d	�
�Gd�d��ZGd
�d�Ze�ZGd�dej0�ZGd�dej4�ZGd�dej8�Zy)zA
Support for starting, monitoring, and restarting child process.
�)�Dict�List�OptionalN)�service)�error�protocol�reactor)�Logger)�basic)�	deprecateT)�frozen�auto_attribsc��eZdZUdZeeed<dZee	ed<dZ
ee	ed<ejeje���Zeeefed<dZeeed<ej&ej*d	d
dd��d
��Zy)�_Processa"
    The parameters of a process to be restarted.

    @ivar args: command-line arguments (including name of command as first one)
    @type args: C{list}

    @ivar uid: user-id to run process as, or None (which means inherit uid)
    @type uid: C{int}

    @ivar gid: group-id to run process as, or None (which means inherit gid)
    @type gid: C{int}

    @ivar env: environment for process
    @type env: C{dict}

    @ivar cwd: initial working directory for process or None
               (which means inherit cwd)
    @type cwd: C{str}
    �argsN�uid�gid)�default�env�cwd�Twisted��rc�^�|j|j|j|jfS)a�
        Convert process to tuple.

        Convert process to tuple that looks like the legacy structure
        of processes, for potential users who inspected processes
        directly.

        This was only an accidental feature, and will be removed. If
        you need to remember what processes were added to a process monitor,
        keep track of that when they are added. The process list
        inside the process monitor is no longer a public API.

        This allows changing the internal structure of the process list,
        when warranted by bug fixes or additional features.

        @return: tuple representation of process
        )rrrr��selfs �8/usr/lib/python3/dist-packages/twisted/runner/procmon.py�toTuplez_Process.toTuple0s#��&�	�	�4�8�8�T�X�X�t�x�x�8�8�)�__name__�
__module__�__qualname__�__doc__r�str�__annotations__rr�intr�attr�ib�Factory�dictrrrr�
deprecated�incremental�Versionr�rrrrs����(�s�)�O��C��#����C��#���!�$�'�'�,�$�,�,�t�*<�=�C��c�3�h��=��C��#����Y���-�+�-�-�i��Q��B�C�9�D�9rrc��eZdZdZy)�DummyTransportrN)r r!r"�
disconnectingr.rrr0r0Fs���Mrr0c�"�eZdZdZdZdZdZd�Zy)�
LineLoggerN�
c���	|jd�}|jjjd|j||j��y#t$rt|�}Y�TwxYw)Nzutf-8z[{tag}] {line})�tag�line�stream)�decode�UnicodeDecodeError�reprr�log�infor6r8)rr7s  r�lineReceivedzLineLogger.lineReceivedSs_��	��;�;�w�'�D�	
��������$�(�(��d�k�k�	�	
��"�	���:�D�	�s�A�A(�'A()r r!r"r6r8�	delimiterrr>r.rrr3r3Ms��
�C�
�F��I��G�
rr3c�L�eZdZdZdZd�Zd�Zd�Zd�Ze	d��Z
e	d��Zy)�LoggingProtocolNc���t�|_|j|j_d|j_|j
|j_d|_t�|_|j|j_d|j_|j
|j_d|_|jjt�|jjt�y)N�stdoutT�stderr)r3�_output�namer6r8r�_outputEmpty�_error�_errorEmpty�makeConnection�	transportrs r�connectionMadezLoggingProtocol.connectionMadebs���!�|����9�9�����&�����#�|�|����� ��� �l����)�)�����%�����"�l�l�����������#�#�I�.����"�"�9�-rc�T�|jj|�|ddk(|_y�N���r4)rE�dataReceivedrG�r�datas  r�outReceivedzLoggingProtocol.outReceivedrs%�����!�!�$�'� ��H��-��rc�T�|jj|�|ddk(|_yrN)rHrPrIrQs  r�errReceivedzLoggingProtocol.errReceivedvs%����� � ��&���8�u�,��rc���|js|jjd�|js|jjd�|j
j
|j�y)Nr4)rGrErPrIrHr�connectionLostrF)r�reasons  r�processEndedzLoggingProtocol.processEndedzsN��� � ��L�L�%�%�e�,�����K�K�$�$�U�+����#�#�D�I�I�.rc��|jS�N)rErs r�outputzLoggingProtocol.output�s���|�|�rc��|jSr[)rGrs r�emptyzLoggingProtocol.empty�s��� � � r)r r!r"rrFrLrSrUrY�propertyr\r^r.rrrArA^sH���G��D�.� .�-�/������!��!rrAc�0�eZdZdZdZdZdZdZe�Z	e
fd�Zejejdddd	��d
��Zej"ejdddd	��d��Zddidfd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zdefd�Zy)�ProcessMonitora

    ProcessMonitor runs processes, monitors their progress, and restarts
    them when they die.

    The ProcessMonitor will not attempt to restart a process that appears to
    die instantly -- with each "instant" death (less than 1 second, by
    default), it will delay approximately twice as long before restarting
    it.  A successful run will reset the counter.

    The primary interface is L{addProcess} and L{removeProcess}. When the
    service is running (that is, when the application it is attached to is
    running), adding a process automatically starts it.

    Each process has a name. This name string must uniquely identify the
    process.  In particular, attempting to add two processes with the same
    name will result in a C{KeyError}.

    @type threshold: C{float}
    @ivar threshold: How long a process has to live before the death is
        considered instant, in seconds.  The default value is 1 second.

    @type killTime: C{float}
    @ivar killTime: How long a process being killed has to get its affairs
        in order before it gets killed with an unmaskable signal.  The
        default value is 5 seconds.

    @type minRestartDelay: C{float}
    @ivar minRestartDelay: The minimum time (in seconds) to wait before
        attempting to restart a process.  Default 1s.

    @type maxRestartDelay: C{float}
    @ivar maxRestartDelay: The maximum time (in seconds) to wait before
        attempting to restart a process.  Default 3600s (1h).

    @type _reactor: L{IReactorProcess} provider
    @ivar _reactor: A provider of L{IReactorProcess} and L{IReactorTime}
        which will be used to spawn processes and register delayed calls.

    @type log: L{Logger}
    @ivar log: The logger used to propagate log messages from spawned
        processes.

    ��ic�f�||_i|_i|_i|_i|_i|_i|_yr[)�_reactor�
_processes�	protocols�delay�timeStarted�murder�restart)rr	s  r�__init__zProcessMonitor.__init__�s4����
���������
���������rrrrrc��|jj�D��cic]\}}||j���c}}Scc}}w)zu
        Processes as dict of tuples

        @return: Dict of process name to monitored processes as tuples
        )rf�itemsr)rrF�processs   r�	processeszProcessMonitor.processes�s6��>B�_�_�=R�=R�=T�U�M�D�'��g�o�o�'�'�U�U��Us�=c��tjj|�}|d=i|d<i|d<i|d<i|d<i|d<|d=|j|d<|S)	Nrergrhrirjrkrfrp)r�Service�__getstate__rp)r�dcts  rrszProcessMonitor.__getstate__�sg���o�o�*�*�4�0���
�O���K����G����M����H�
���I������>�>��K���
rNc���||jvrtd|�d���t|||||�|j|<|j|j|<|j
r|j
|�yy)a
        Add a new monitored process and start it immediately if the
        L{ProcessMonitor} service is running.

        Note that args are passed to the system call, not to the shell. If
        running the shell is desired, the common idiom is to use
        C{ProcessMonitor.addProcess("name", ['/bin/sh', '-c', shell_script])}

        @param name: A name for this process.  This value must be
            unique across all processes added to this monitor.
        @type name: C{str}
        @param args: The argv sequence for the process to launch.
        @param uid: The user ID to use to run the process.  If L{None},
            the current UID is used.
        @type uid: C{int}
        @param gid: The group ID to use to run the process.  If L{None},
            the current GID is used.
        @type uid: C{int}
        @param env: The environment to give to the launched process. See
            L{IReactorProcess.spawnProcess}'s C{env} parameter.
        @type env: C{dict}
        @param cwd: The initial working directory of the launched process.
            The default of C{None} means inheriting the laucnhing process's
            working directory.
        @type env: C{dict}
        @raise KeyError: If a process with the given name already exists.
        zremove z firstN)rf�KeyErrorr�minRestartDelayrh�running�startProcess)rrFrrrrrs       r�
addProcesszProcessMonitor.addProcess�sm��8�4�?�?�"��W�T�F�&�1�2�2� (��s�C��c� B�������/�/��
�
�4���<�<����d�#�rc�@�|j|�|j|=y)z�
        Stop the named process and remove it from the list of monitored
        processes.

        @type name: C{str}
        @param name: A string that uniquely identifies the process.
        N)�stopProcessrf�rrFs  r�
removeProcesszProcessMonitor.removeProcesss��	
������O�O�D�!rc��tjj|�t|j�D]}|j|��y)z0
        Start all monitored processes.
        N)rrr�startService�listrfryr}s  rr�zProcessMonitor.startServices<��	���$�$�T�*�����)�	$�D����d�#�	$rc�0�tjj|�t|jj��D]&\}}|j
�s�|j��(t|j�D]}|j|��y)zY
        Stop all monitored processes and cancel all scheduled process restarts.
        N)
rrr�stopServicer�rkrn�active�cancelrfr|)rrF�delayedCalls   rr�zProcessMonitor.stopServices~��	���#�#�D�)�"&�d�l�l�&8�&8�&:�!;�	%��D�+��!�!�#��"�"�$�	%�����)�	#�D����T�"�	#rc��||jvrG|j|j�r|j|j�|j|=|j|=|jj�|j|z
|jkrC|j|}t|j|dz|j�|j|<nd}|j|j|<|jrD||jvr5|jj||j|�|j |<yyy)a�
        Called when a monitored processes exits. If
        L{service.IService.running} is L{True} (ie the service is started), the
        process will be restarted.
        If the process had been running for more than
        L{ProcessMonitor.threshold} seconds it will be restarted immediately.
        If the process had been running for less than
        L{ProcessMonitor.threshold} seconds, the restart will be delayed and
        each time the process dies before the configured threshold, the restart
        delay will be doubled - up to a maximum delay of maxRestartDelay sec.

        @type name: C{str}
        @param name: A string that uniquely identifies the process
            which exited.
        �rN)rjr�r�rgre�secondsri�	thresholdrh�min�maxRestartDelayrwrxrf�	callLaterryrk)rrF�	nextDelays   rrWzProcessMonitor.connectionLost!s��$�4�;�;���{�{�4� �'�'�)����D�!�(�(�*����D�!��N�N�4� ��=�=� � �"�T�%5�%5�d�%;�;�d�n�n�L��
�
�4�(�I�"�4�:�:�d�#3�a�#7��9M�9M�N�D�J�J�t��
�I�#�3�3�D�J�J�t���<�<�D�D�O�O�3�!%���!8�!8��4�,�,�d�"�D�L�L���4�<rc	��||jvry|j|}t�}||_||_||j|<|j
j
�|j|<|j
j||jd|j|j|j|j|j��y)zD
        @param name: The name of the process to be started
        Nr)rrr�path)rgrfrArrFrer�ri�spawnProcessrrrrr)rrFro�protos    rryzProcessMonitor.startProcessKs����4�>�>�!���/�/�$�'���!����
���
�$����t��!%���!6�!6�!8�������
�
�"�"���L�L��O��L�L�������������	#�	
rc�Z�	|jd�y#tj$rYywxYw)z?
        @param proc: An L{IProcessTransport} provider
        �KILLN)�
signalProcessr�ProcessExitedAlready)r�procs  r�_forceStopProcessz ProcessMonitor._forceStopProcesses-��	����v�&���)�)�	��	�s��*�*c�d�||jvrtd|����|jj|d�}|�]|j}	|jd�|jj|j|j|�|j|<yy#tj$rYywxYw)zD
        @param name: The name of the process to be stopped
        zUnrecognized process name: N�TERM)
rfrvrg�getrKr�rer��killTimer�rjrr�)rrFr�r�s    rr|zProcessMonitor.stopProcessns����t���&��8���?�@�@����"�"�4��.�����?�?�D�
��"�"�6�*�%)�M�M�$;�$;��M�M�4�#9�#9�4�%����D�!����-�-�
��
�s�B�B/�.B/c�H�|jD]}|j|��y)z�
        Restart all processes. This is useful for third party management
        services to allow a user to restart servers because of an outside change
        in circumstances -- for example, a new version of a library is
        installed.
        N)rfr|r}s  r�
restartAllzProcessMonitor.restartAll�s%���O�O�	#�D����T�"�	#r�returnc��g}|jj�D]{\}}d}|j�t|j�}|j�|dt|j�zz
}|rd|zdz}|j|�|�d|j����}d|jjzdzdj|�zdzS)	N��:�(�)z: �<� �>)
rfrnrr$r�appendr�	__class__r �join)r�lstrFr��uidgids     r�__repr__zProcessMonitor.__repr__�s������/�/�/�/�1�		;�J�D�$��F��x�x�#��T�X�X����x�x�#��#��D�H�H�
�-�-����v���+���J�J�$��&���D�I�I�=�9�:�		;��T�^�^�,�,�,�s�2�S�X�X�c�]�B�S�H�Hr)r r!r"r#r�r�rwr�r
r<rerlr�deprecatedPropertyr,r-rpr+rsrzr~r�r�rWryr�r|r�r$r�r.rrrara�s���*�X�I��H��O��O�
�(�C�'��"�Y�!�!�"5�+�"5�"5�i��Q��"J�K�V�L�V��Y���-�+�-�-�i��Q��B�C�
�D�
�*.�4�R�T�!$�F	"�$�#�(�T
�4��&#�I�#�Irra)r#�typingrrrr'r,�twisted.applicationr�twisted.internetrrr	re�twisted.loggerr
�twisted.protocolsr�twisted.pythonr�srr0rK�LineReceiverr3�ProcessProtocolrArrrar.rr�<module>r�s���
�(�'���'�A�A�!�#�$�����t�$�'�.9�.9�(�.9�b��
��	�
��#�#�
�")!�h�.�.�)!�XMI�W�_�_�MIr

Zerion Mini Shell 1.0