Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
process.cpython-313.pyc139 linesDownload Raw Back to __pycache__
1�

2��j3��R�SrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJ	r	 SSK3JrJrJ
r
 SSKJr SSKJr SSKJr SSKrSSKJrJrJr \R0(aSS	KJr \R4rS4\4SjrSSjrSqSS
\\S\\S5\4SjjrS6\\4Sjr "SS5r!g)z�Utilities for working with multiple processes, including both forking7the server into multiple processes and managing subprocesses.8�N)�hexlify)�Future�"future_set_result_unless_cancelled�%future_set_exception_unless_cancelled)�ioloop)�PipeIOStream)�gen_log)�Optional�Any�Callable)�List�returnc���[cg[R"5$![a Of=f[R"S5$![9[4a Of=f[R"S5 g)z1Returns the number of processors on this machine.��SC_NPROCESSORS_CONFz1Could not detect number of processors; assuming 1)	�multiprocessing�	cpu_count�NotImplementedError�os�sysconf�AttributeError�10ValueErrorr	�error���UD:\code\apps\devtools\python\user_packages\Python313\site-packages\tornado/process.pyrr1sm�����
��(�(�*�*���
��
��
��z�z�/�0�0���J�'�
��
���M�M�E�F�s��11,�,�A�A�Ac�:�S[R;agSSKn[[	[12R"S55S5nURU5 g![a: [[R"5S-5[13R"5-nNUf=f)N�randomr�i�)�sys�modulesr�intrr�urandomr�time�getpid�seed)rr&s  r�_reseed_randomr'Asq���s�{�{�"���145��7�2�:�:�b�>�*�B�/���K�K�����5��4�9�9�;��%�&�����4��5�s�)A�AB�B�
num_processes�max_restartsc�|^	�[RS:Xa[S5eUcSn[beUbUS::a15[	5n[16R"SU5 0m	S[S[[4U	4S	jjn[U5HnU"U5nUcMUs $ SnT	(Ga[R"5upgUT	;aM'T	RU5n[R"U5(a.[17R"S18UU[R"U55 Oa[R "U5S:wa.[19R"SUU[R "U55 O[20R"SXF5 M�US
-
nXQ:�a[#S5eU"U5nUbU$T	(aGM[R$"S5 g)a!Starts multiple worker processes.21 22If ``num_processes`` is None or <= 0, we detect the number of cores23available on this machine and fork that number of child24processes. If ``num_processes`` is given and > 0, we fork that25specific number of sub-processes.26 27Since we use processes and not threads, there is no shared memory28between any server code.29 30Note that multiple processes are not compatible with the autoreload31module (or the ``autoreload=True`` option to `tornado.web.Application`32which defaults to True when ``debug=True``).33When using multiple processes, no IOLoops can be created or34referenced until after the call to ``fork_processes``.35 36In each child process, ``fork_processes`` returns its *task id*, a37number between 0 and ``num_processes``.  Processes that exit38abnormally (due to a signal or non-zero exit status) are restarted39with the same id (up to ``max_restarts`` times).  In the parent40process, ``fork_processes`` calls ``sys.exit(0)`` after all child41processes have exited normally.42 43max_restarts defaults to 100.44 45Availability: Unix46�win32zfork not available on windowsN�drzStarting %d processes�irc�b>�[R"5nUS:Xa[5 UqU$UTU'g�Nr)r�forkr'�_task_id)r-�pid�childrens  �r�start_child�#fork_processes.<locals>.start_childs1����g�g�i���!�8����H��H��H�S�M�rz1child %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)r �platform�	Exceptionr1rr	�infor"r47�ranger�wait�pop�WIFSIGNALED�warning�WTERMSIG�WEXITSTATUS�RuntimeError�exit)48r(r)r4r-�id�num_restartsr2�status�new_idr3s49         @r�fork_processesrFSs����<�|�|�w���7�8�8�����������
�� 2�!��
��L�L�(�-�8��H�50�s�51�x��}�52��=�
!��
��^��
�>��I�"��L�53��g�g�i����h���
�\�\�#�
��
�>�>�&�!�!��O�O�C������F�#�	
��^�^�F�
#�q�
(��O�O�E������v�&�	
�
�L�L�<�b�F�������&��C�D�D��R������M�7�(�@�H�H�Q�Krc��[$)zhReturns the current task id, if any.54 55Returns None if this process was not created by `fork_processes`.56)r1rrr�task_idrH�s	���Orc���\rSrSrSr\"5rSr0rS\	S\	SS4Sjr57S	\\/S4SS4S58jr
SS\SS4S
jjr\SSj5r\SSj5r\SSj5r\S\SS4Sj5rS\SS4SjrSrg)�59Subprocess�a�Wraps ``subprocess.Popen`` with IOStream support.60 61The constructor is the same as ``subprocess.Popen`` with the following62additions:63 64* ``stdin``, ``stdout``, and ``stderr`` may have the value65  ``tornado.process.Subprocess.STREAM``, which will make the corresponding66  attribute of the resulting Subprocess a `.PipeIOStream`. If this option67  is used, the caller is responsible for closing the streams when done68  with them.69 70The ``Subprocess.STREAM`` option and the ``set_exit_callback`` and71``wait_for_exit`` methods do not work on Windows. There is72therefore no reason to use this class instead of73``subprocess.Popen`` on that platform.74 75.. versionchanged:: 5.076   The ``io_loop`` argument (deprecated since version 4.1) has been removed.77 78F�args�kwargsrNc	�z�[RR5Ul/n/nUR	S5[79RLaN[R"5upVXRS'URXV45 URU5 [U5UlUR	S5[80RLaN[R"5upxX�S'URXx45 URU5 [U5Ul
UR	S5[81RLaN[R"5up�X�S'URX�45 URU825 [U	5Ul[R "U0UD6UlUHn[R$"U5 M UR"R&UlSH5n[)X5(aM[+X[-UR"U55 M7 SUlSUlg! UHn[R$"U5 M e=f)N�stdin�stdout�stderr)rOrPrQ)r�IOLoop�current�io_loop�getrJ�STREAMr�pipe�extend�appendrrOrPrQ�83subprocess�Popen�proc�closer2�hasattr�setattr�getattr�_exit_callback�84returncode)
�selfrLrM�pipe_fds�to_close�in_r�in_w�out_r�out_w�err_r�err_w�fd�attrs
             r�__init__�Subprocess.__init__�s����}�}�,�,�.��������:�:�g��*�"3�"3�3�����J�D�"�7�O��O�O�T�L�)��O�O�D�!�%�d�+�D�J��:�:�h��:�#4�#4�4��7�7�9�L�E�$�8���O�O�U�N�+��O�O�E�"�&�u�-�D�K��:�:�h��:�#4�#4�4��7�7�9�L�E�$�8���O�O�U�N�+��O�O�E�"�&�u�-�D�K�	�"�(�(�$�9�&�9�D�I�85�B��H�H�R�L���9�9�=�=���1�D��4�&�&���G�D�I�I�t�$<�=�2�#�������	����������s�9H�"H:�callbackc��Xl[R5 U[RUR'[RUR5 g)aNRuns ``callback`` when this process exits.86 87The callback takes one argument, the return code of the process.88 89This method uses a ``SIGCHLD`` handler, which is a global setting90and may conflict if you have other libraries trying to handle the91same signal.  If you are using more than one ``IOLoop`` it may92be necessary to call `Subprocess.initialize` first to designate93one ``IOLoop`` to run the signal handlers.94 95In many cases a close callback on the stdout or stderr streams96can be used as an alternative to an exit callback if the97signal handler is causing a problem.98 99Availability: Unix100N)rarJ�101initialize�_waitingr2�_try_cleanup_process)rcrps  r�set_exit_callback�Subprocess.set_exit_callback�s<��"'������(,�102���D�H�H�%��'�'����1r�raise_errorzFuture[int]c�b^^�[5mS[SS4UU4SjjnURU5 T$)a�Returns a `.Future` which resolves when the process exits.103 104Usage::105 106    ret = yield proc.wait_for_exit()107 108This is a coroutine-friendly alternative to `set_exit_callback`109(and a replacement for the blocking `subprocess.Popen.wait`).110 111By default, raises `subprocess.CalledProcessError` if the process112has a non-zero exit status. Use ``wait_for_exit(raise_error=False)``113to suppress this behavior and return the exit status without raising.114 115.. versionadded:: 4.2116 117Availability: Unix118�retrNc�f>�US:waT(a[T[US55 g[TU5 g)Nr�unknown)r�CalledProcessErrorr)ry�futurerws ��rrp�*Subprocess.wait_for_exit.<locals>.callback(s-����a�x�K�5��.�s�I�>��3�6�3�?r)rr"ru)rcrwrpr}s ` @r�
wait_for_exit�Subprocess.wait_for_exits=���$���	@�#�	@�$�	@�	@�	
���x�(��
rc��UR(ag[R"5nUR[R119UR5 SUlg)a�Initializes the ``SIGCHLD`` handler.120 121The signal handler is run on an `.IOLoop` to avoid locking issues.122Note that the `.IOLoop` used for signal handling need not be the123same one used by individual Subprocess objects (as long as the124``IOLoops`` are each running in separate threads).125 126.. versionchanged:: 5.0127   The ``io_loop`` argument (deprecated since version 4.1) has been128   removed.129 130Availability: Unix131NT)�_initialized�asyncio�get_event_loop�add_signal_handler�signal�SIGCHLD�_cleanup��cls�loops  rrr�Subprocess.initialize4s>�������%�%�'�����������=���rc��UR(dg[R"5nUR[R1325 SUlg)z Removes the ``SIGCHLD`` handler.NF)r�r�r��remove_signal_handlerr�r�r�s  r�uninitialize�Subprocess.uninitializeIs8�������%�%�'���"�"�6�>�>�2� ��rc�z�[URR55HnURU5 M g�N)�listrs�keysrt)r�r2s  rr��Subprocess._cleanupRs,������)�)�+�,�C��$�$�S�)�-rr2c��[R"U[R5up#US:XagX!:XdeURRU5nURRURU5 g![a gf=fr/)	r�waitpid�WNOHANG�ChildProcessErrorrsr;rT�add_callback�_set_returncode)r�r2�ret_pidrD�subprocs     rrt�Subprocess._try_cleanup_processWsu��	� �j�j��b�j�j�9�O�G��a�<���~��~��,�,�"�"�3�'�����$�$�W�%<�%<�f�E��
!�	��	�s�'A9�9133B�BrDc���[RS:XaSUlOp[R"U5(a[R134"U5*UlO8[R"U5(de[R"U5UlURURlUR(a&URnSUl	U"UR5 gg)Nr+�����)135r r6rbrr<r>�	WIFEXITEDr?r\ra)rcrDrps   rr��Subprocess._set_returncodecs����<�<�7�"� �D�O��~�~�f�%�%�#%�;�;�v�#6�"6����|�|�F�+�+�+�+�"$�.�.��"8��� $����	�	������*�*�H�"&�D���T�_�_�%�r)rarTr2r\rbrQrOrP)T�rN)�__name__�136__module__�__qualname__�__firstlineno__�__doc__�objectrVr�rsrrnrr"ru�boolr�classmethodrrr�r�rtr��__static_attributes__rrrrJrJ�s����*�X�F��L��H�%�c�%�S�%�T�%�N2�(�C�5�$�;�*?�2�D�2�,�����@� �� �(�!��!��*��*��	F�s�	F�t�	F��	F�&�c�&�d�&rrJr�r�)"r�r�rrr�rZr r$�binasciir�tornado.concurrentrrr�tornador�tornado.iostreamr�tornado.logr	�typingr137rr�
TYPE_CHECKINGr
r|r"rr'r1rFrHrJrrr�<module>r�s��� ��	��
��138�����139�)��
�*�*�	���� �2�2��

�3�

� ���AE�]��C�=�]�08��
�]��]�@��#���w&�w&r
codekingpro/portable-devtools · Team Ai