BYPASS SHELL BY ./RAZORGANZ
Server: nginx/1.20.1
System: Linux iZdzfnv9mwfppeZ 5.10.134-19.2.al8.x86_64 #1 SMP Wed Oct 29 22:47:09 CST 2025 x86_64
User: apache (48)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //lib64/python3.6/site-packages/tornado/__pycache__/process.cpython-36.pyc
3

	��f2�@sDdZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZmZm
Z
ddlmZddlmZddlmZddlmZdd	lmZddlZdd
lmZmZmZmZejr�ddlmZejZe d�d
d�Z!dd�dd�Z"ee e fd�dd�Z#da$dee e e d�dd�Z%ee d�dd�Z&Gdd�de'�Z(dS)z�Utilities for working with multiple processes, including both forking
the server into multiple processes and managing subprocesses.
�N)�hexlify)�Future�"future_set_result_unless_cancelled�%future_set_exception_unless_cancelled)�ioloop)�PipeIOStream)�gen_log)�set_close_exec)�errno_from_exception)�Tuple�Optional�Any�Callable)�List)�returncCs\tdkrdSytj�Stk
r(YnXy
tjd�Sttfk
rLYnXtjd�dS)z1Returns the number of processors on this machine.N��SC_NPROCESSORS_CONFz1Could not detect number of processors; assuming 1)	�multiprocessing�	cpu_count�NotImplementedError�os�sysconf�AttributeError�
ValueErrorr�error�rr�/usr/lib64/python3.6/process.pyr3s

rcCsjdtjkrdSddl}ytttjd��d�}Wn,tk
rZttj�d�tj	�A}YnX|j
|�dS)N�randomr�i�)�sys�modulesr�intrr�urandomr�time�getpid�seed)rr%rrr�_reseed_randomCs
r&cCs$tj�\}}t|�t|�||fS)N)r�piper	)�r�wrrr�
_pipe_cloexecRsr*)�
num_processes�max_restartsrc
s~|dkrd}tdkst�|dks(|dkr.t�}tjd|�i�tttd��fdd�}x$t|�D]}||�}|dk	r`|Sq`Wd}x��rnytj	�\}}Wn4t
k
r�}zt|�tj
kr�w��WYdd}~XnX|�kr�q��j|�}tj|��rtjd||tj|��n8tj|�dk�r.tjd	||tj|��ntjd
||�q�|d7}||k�rXtd��||�}	|	dk	r�|	Sq�Wtjd�dS)
a�Starts multiple worker processes.

    If ``num_processes`` is None or <= 0, we detect the number of cores
    available on this machine and fork that number of child
    processes. If ``num_processes`` is given and > 0, we fork that
    specific number of sub-processes.

    Since we use processes and not threads, there is no shared memory
    between any server code.

    Note that multiple processes are not compatible with the autoreload
    module (or the ``autoreload=True`` option to `tornado.web.Application`
    which defaults to True when ``debug=True``).
    When using multiple processes, no IOLoops can be created or
    referenced until after the call to ``fork_processes``.

    In each child process, ``fork_processes`` returns its *task id*, a
    number between 0 and ``num_processes``.  Processes that exit
    abnormally (due to a signal or non-zero exit status) are restarted
    with the same id (up to ``max_restarts`` times).  In the parent
    process, ``fork_processes`` returns None if all child processes
    have exited normally, but will otherwise only exit by throwing an
    exception.

    max_restarts defaults to 100.
    N�drzStarting %d processes)�ircs.tj�}|dkrt�|a|S|�|<dSdS)Nr)r�forkr&�_task_id)r.�pid)�childrenrr�start_child�sz#fork_processes.<locals>.start_childz1child %d (pid %d) killed by signal %d, restartingz3child %d (pid %d) exited with status %d, restartingz!child %d (pid %d) exited normallyrz"Too many child restarts, giving up)r0�AssertionErrorrr�infor!r�ranger�wait�OSErrorr
�errnoZEINTR�pop�WIFSIGNALEDZwarning�WTERMSIG�WEXITSTATUS�RuntimeErrorr�exit)
r+r,r3r.�idZnum_restartsr1�status�eZnew_idr)r2r�fork_processes\sX

rCcCstS)zpReturns the current task id, if any.

    Returns None if this process was not created by `fork_processes`.
    )r0rrrr�task_id�srDc@s�eZdZdZe�ZdZiZdZe	e	dd�dd�Z
eegdfdd�dd	�Z
dedd�d
d�Zedd�dd��Zedd�dd��Zedd�dd��Zeedd�dd��Zedd�dd�ZdS)�
Subprocessa Wraps ``subprocess.Popen`` with IOStream support.

    The constructor is the same as ``subprocess.Popen`` with the following
    additions:

    * ``stdin``, ``stdout``, and ``stderr`` may have the value
      ``tornado.process.Subprocess.STREAM``, which will make the corresponding
      attribute of the resulting Subprocess a `.PipeIOStream`. If this option
      is used, the caller is responsible for closing the streams when done
      with them.

    The ``Subprocess.STREAM`` option and the ``set_exit_callback`` and
    ``wait_for_exit`` methods do not work on Windows. There is
    therefore no reason to use this class instead of
    ``subprocess.Popen`` on that platform.

    .. versionchanged:: 5.0
       The ``io_loop`` argument (deprecated since version 4.1) has been removed.

    FN)�args�kwargsrc

Os�tjj�|_g}g}|jd�tjkrXt�\}}||d<|j||f�|j	|�t
|�|_|jd�tjkr�t�\}}||d<|j||f�|j	|�t
|�|_|jd�tjkr�t�\}	}
|
|d<|j|	|
f�|j	|
�t
|	�|_
ytj||�|_Wn(x|D]}tj|��qW�YnXx|D]}tj|��q"W|jj|_x.dD]&}t||��sFt||t|j|���qFWd|_d|_dS)N�stdin�stdout�stderr)rHrIrJ)r�IOLoop�current�io_loop�getrE�STREAMr*�extend�appendrrHrIrJ�
subprocess�Popen�procr�closer1�hasattr�setattr�getattr�_exit_callback�
returncode)
�selfrFrGZpipe_fdsZto_closeZin_rZin_wZout_rZout_wZerr_rZerr_w�fd�attrrrr�__init__�sF












zSubprocess.__init__)�callbackrcCs*||_tj�|tj|j<tj|j�dS)a�Runs ``callback`` when this process exits.

        The callback takes one argument, the return code of the process.

        This method uses a ``SIGCHLD`` handler, which is a global setting
        and may conflict if you have other libraries trying to handle the
        same signal.  If you are using more than one ``IOLoop`` it may
        be necessary to call `Subprocess.initialize` first to designate
        one ``IOLoop`` to run the signal handlers.

        In many cases a close callback on the stdout or stderr streams
        can be used as an alternative to an exit callback if the
        signal handler is causing a problem.
        N)rYrE�
initialize�_waitingr1�_try_cleanup_process)r[r_rrr�set_exit_callbackszSubprocess.set_exit_callbackTzFuture[int])�raise_errorrcs*t��tdd���fdd�}|j|��S)aReturns a `.Future` which resolves when the process exits.

        Usage::

            ret = yield proc.wait_for_exit()

        This is a coroutine-friendly alternative to `set_exit_callback`
        (and a replacement for the blocking `subprocess.Popen.wait`).

        By default, raises `subprocess.CalledProcessError` if the process
        has a non-zero exit status. Use ``wait_for_exit(raise_error=False)``
        to suppress this behavior and return the exit status without raising.

        .. versionadded:: 4.2
        N)�retrcs,|dkr�rt�t|d��n
t�|�dS)Nr�unknown)r�CalledProcessErrorr)re)�futurerdrrr_,sz*Subprocess.wait_for_exit.<locals>.callback)rr!rc)r[rdr_r)rhrdr�
wait_for_exits	
zSubprocess.wait_for_exit)rcs8�jr
dStjj��tjtj��fdd���_d�_dS)a�Initializes the ``SIGCHLD`` handler.

        The signal handler is run on an `.IOLoop` to avoid locking issues.
        Note that the `.IOLoop` used for signal handling need not be the
        same one used by individual Subprocess objects (as long as the
        ``IOLoops`` are each running in separate threads).

        .. versionchanged:: 5.0
           The ``io_loop`` argument (deprecated since version 4.1) has been
           removed.
        Ncs�j�j�S)N)�add_callback_from_signal�_cleanup)Zsig�frame)�clsrMrr�<lambda>Jsz'Subprocess.initialize.<locals>.<lambda>T)�_initializedrrKrL�signal�SIGCHLD�_old_sigchld)rmr)rmrMrr`8s

zSubprocess.initializecCs$|js
dStjtj|j�d|_dS)z Removes the ``SIGCHLD`` handler.NF)rorprqrr)rmrrr�uninitializeNszSubprocess.uninitializecCs&x t|jj��D]}|j|�qWdS)N)�listra�keysrb)rmr1rrrrkVszSubprocess._cleanup)r1rcCs�ytj|tj�\}}Wn4tk
rJ}zt|�tjkr:dSWYdd}~XnX|dkrXdS||ksdt�|jj	|�}|j
j|j|�dS)Nr)
r�waitpid�WNOHANGr8r
r9ZECHILDr4rar:rMrj�_set_returncode)rmr1Zret_pidrArBZsubprocrrrrb[szSubprocess._try_cleanup_process)rArcCs^tj|�rtj|�|_ntj|�s(t�tj|�|_|j|j_|jrZ|j}d|_||j�dS)N)	rr;r<rZ�	WIFEXITEDr4r=rTrY)r[rAr_rrrrxhs

zSubprocess._set_returncode)T)�__name__�
__module__�__qualname__�__doc__�objectrOrorarrr
r^rr!rc�boolri�classmethodr`rsrkrbrxrrrrrE�s"'rE)N))r}r9rrrprRrr#ZbinasciirZtornado.concurrentrrrZtornadorZtornado.iostreamrZtornado.logrZtornado.platform.autor	Ztornado.utilr
Ztypingrrr
rZ
TYPE_CHECKINGrrgr!rr&r*r0rCrDr~rErrrr�<module>s4^