+
    ‚V@i˜1  ã                   ó6  € R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
HtHtHt ^ RIHt ^ RIHt ^ RIHt ^ RIt^ RIHtHtHt ]P0                  '       d   ^ RIHt ]P4                  tR	 R
 ltR R ltRsRR R lltR R lt ! R R4      t R# )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)ÚOptionalÚAnyÚCallable)ÚListc                ó$   € V ^8„  d   QhR\         /# ©é   Úreturn©Úint)Úformats   "Ú1/usr/lib/python3/dist-packages/tornado/process.pyÚ__annotate__r   1   s   € ÷ ñ ”3ñ ó    c                 óð   € \         f   ^#  \         P                  ! 4       #   \         d     Mi ; i \        P                  ! R4      #   \
        \        3 d     Mi ; i\        P                  ! R4       ^# )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Ú
ValueErrorr   Úerror© r   r   r   r   1   sm   € äÒÙðÜ×(Ò(Ó*Ð*øÜô ÙðúðÜ�zŠzÐ/Ó0Ð0øÜœJÐ'ô Ùðúä‡M‚MÐEÔFÙs   Œ! ¡/®/³A	 Á	AÁAc                ó   € V ^8„  d   QhRR/# ©r   r   Nr!   )r   s   "r   r   r   A   s   € ÷ ñ ˜ñ r   c                  óR  € R \         P                  9  d   R# ^ RIp  \        \	        \
        P                  ! ^4      4      ^4      pV P                  V4       R#   \         dC    \        \        P                  ! 4       R,          4      \
        P                  ! 4       ,          p L_i ; i)ÚrandomNiè  )ÚsysÚmodulesr%   r   r   r   Úurandomr   ÚtimeÚgetpidÚseed)r%   r+   s     r   Ú_reseed_randomr,   A   sq   € Ø”s—{‘{Ô"ÙÛð
5Ü”7œ2Ÿ:š: b›>Ó*¨BÓ/ˆð ‡K�K�Öøô ô 5Ü”4—9’9“; Õ%Ó&¬¯ª«Õ4Šð5ús   �)A ÁA
B&Â%B&c                óh   € V ^8„  d   QhR\         \        ,          R\         \        ,          R\        /# )r   Únum_processesÚmax_restartsr   ©r	   r   )r   s   "r   r   r   S   s1   € ÷ ]ñ ]ÜœC•=ð]Ü08¼µð]äñ]r   c                ól  a	€ \         P                  R8X  d   \        R4      hVf   ^dp\        e   Q hV e   V ^ 8:  d   \	        4       p \
        P                  ! RV 4       / o	R V	3R llp\        V 4       F  pV! V4      pVf   K  Vu # 	  ^ pS	'       Ed	   \        P                  ! 4       w  rgVS	9  d   K)  S	P                  V4      p\        P                  ! V4      '       d/   \
        P                  ! RVV\        P                  ! V4      4       Mb\        P                  ! V4      ^ 8w  d/   \
        P                  ! RVV\        P                  ! V4      4       M\
        P                  ! R	WF4       Kæ  V^,          pWQ8”  d   \        R
4      hV! V4      pVf   EK  V# \         P                   ! ^ 4       R# )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`` calls ``sys.exit(0)`` after all child
processes have exited normally.

max_restarts defaults to 100.

Availability: Unix
Úwin32zfork not available on windowsNzStarting %d processesc                óF   € V ^8„  d   QhR\         R\        \         ,          /# )r   Úir   )r   r	   )r   s   "r   r   Ú$fork_processes.<locals>.__annotate__   s   € ÷ 
ñ 
”sð 
œx¬�}ñ 
r   c                 óf   <€ \         P                  ! 4       pV^ 8X  d   \        4        V sV # V SV&   R# )é    N)r   Úforkr,   Ú_task_id)r4   ÚpidÚchildrens   & €r   Ústart_childÚ#fork_processes.<locals>.start_child   s1   ø€ Ü�gŠg‹iˆØ�!Œ8äÔàˆHØˆHàˆH�S‰MÙr   z1child %d (pid %d) killed by signal %d, restartingz3child %d (pid %d) exited with status %d, restartingz!child %d (pid %d) exited normallyz"Too many child restarts, giving up)r&   ÚplatformÚ	Exceptionr9   r   r   ÚinfoÚranger   ÚwaitÚpopÚWIFSIGNALEDÚwarningÚWTERMSIGÚWEXITSTATUSÚRuntimeErrorÚexit)
r.   r/   r<   r4   ÚidÚnum_restartsr:   ÚstatusÚnew_idr;   s
   &&       @r   Úfork_processesrN   S   su  ø€ ô< ‡|�|�wÔô Ð7Ó8Ð8ØÒØˆô ÒÐÐØÒ °Ô 2Ü!›ˆÜ‡L‚LÐ(¨-Ô8Ø€H÷
ð 
ô �=Ö!ˆÙ˜‹^ˆØŒ>ØŠIñ "ð €Lß
ˆ(Ü—g’g“i‰ˆØ�hÔÙØ�\‰\˜#ÓˆÜ�>Š>˜&×!Ò!Ü�OŠOØCØØÜ—’˜FÓ#õ	ô �^Š^˜FÓ# qÔ(Ü�OŠOØEØØÜ—’˜vÓ&õ	ô �LŠLÐ<¸bÔFÙØ˜ÕˆØÔ&ÜÐCÓDÐDÙ˜R“ˆØÕØˆMô
 ‡H‚HˆQ†Kr   c                ó:   € V ^8„  d   QhR\         \        ,          /# r   r0   )r   s   "r   r   r   ³   s   € ÷ ñ ”œ#•ñ r   c                 ó   € \         # )zhReturns the current task id, if any.

Returns None if this process was not created by `fork_processes`.
)r9   r!   r   r   Útask_idrQ   ³   s	   € ô €Or   c                   óö   a € ] tR t^¼t o Rt]! 4       tRt/ tV 3R lR lt	V 3R lR lt
RV 3R lR llt]V 3R	 lR
 l4       t]V 3R lR l4       t]V 3R lR l4       t]V 3R lR l4       tV 3R lR ltRtV tR# )Ú
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.

Fc                ó*   <€ V ^8„  d   QhRS[ RS[ RR/# )r   ÚargsÚkwargsr   N)r
   )r   Ú__classdict__s   "€r   r   ÚSubprocess.__annotate__×   s"   ø€ ÷ %ñ %™cð %©Sð %°Tñ %r   c           	     ó„  € \         P                  P                  4       V n        . p. pVP	                  R 4      \
        P                  J dO   \        P                  ! 4       w  rVWRR &   VP                  WV34       VP                  V4       \        V4      V n        VP	                  R4      \
        P                  J dO   \        P                  ! 4       w  rxW‚R&   VP                  Wx34       VP                  V4       \        V4      V n        VP	                  R4      \
        P                  J dO   \        P                  ! 4       w  ršW¢R&   VP                  Wš34       VP                  V
4       \        V	4      V n         \        P                   ! V/ VB V n        T F  p\        P$                  ! T4       K  	  T P"                  P&                  T n        R F6  p\)        Y4      '       d   K  \+        Y\-        T P"                  T4      4       K8  	  RT n        RT n        R#    T F  p\        P$                  ! T4       K  	  h ; i)ÚstdinÚstdoutÚstderrN)rZ   r[   r\   )r   ÚIOLoopÚcurrentÚio_loopÚgetrS   ÚSTREAMr   ÚpipeÚextendÚappendr   rZ   r[   r\   Ú
subprocessÚPopenÚprocÚcloser:   ÚhasattrÚsetattrÚgetattrÚ_exit_callbackÚ
returncode)ÚselfrU   rV   Ú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ó
 ˆBÜ�HŠH�RŽLñ à—9‘9—=‘=ˆŒÛ1ˆDÜ˜4×&Ô&Ü˜¤G¨D¯I©I°tÓ$<Ö=ñ 2ð #ˆÔØˆŽøð	Û�Ü—’˜–ñ àús   Å<H È"H?c                ó:   <€ V ^8„  d   QhRS[ S[.R3,          RR/# )r   ÚcallbackNr   )r   r   )r   rW   s   "€r   r   rX   þ   s&   ø€ ÷ 2ñ 2©(±C°5¸$°;Õ*?ð 2ÀDñ 2r   c                ó²   € Wn         \        P                  4        V \        P                  V P                  &   \        P                  V P                  4       R# )aN  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.

Availability: Unix
N)rl   rS   Ú
initializeÚ_waitingr:   Ú_try_cleanup_process)rn   r|   s   &&r   Úset_exit_callbackÚSubprocess.set_exit_callbackþ   s<   € ð" 'ÔÜ×ÑÔØ(,Œ
×Ñ˜DŸH™HÑ%Ü×'Ñ'¨¯©Ö1r   c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   Úraise_errorr   zFuture[int])Úbool)r   rW   s   "€r   r   rX     s   ø€ ÷ ñ ©ð ¸ñ r   c                óT   aa€ \        4       oR VV3R llpV P                  V4       S# )aâ  Returns 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

Availability: Unix
c                ó(   € V ^8„  d   QhR\         RR/# )r   Úretr   Nr   )r   s   "r   r   Ú.Subprocess.wait_for_exit.<locals>.__annotate__(  s   € ÷ 	@ñ 	@œ#ð 	@ $ñ 	@r   c                 ón   <€ V ^ 8w  d!   S'       d   \        S\        V R4      4       R# \        SV 4       R# )r7   ÚunknownN)r   ÚCalledProcessErrorr   )rˆ   Úfuturer„   s   &€€r   r|   Ú*Subprocess.wait_for_exit.<locals>.callback(  s-   ø€ Ø�aŒxŸKä5ØÔ.¨s°IÓ>öô 3°6¸3Ö?r   )r   r�   )rn   r„   r|   r�   s   &f @r   Úwait_for_exitÚSubprocess.wait_for_exit  s-   ù€ ô$ “ˆ÷	@ñ 	@ð 	×Ñ˜xÔ(Øˆr   c                ó   <€ V ^8„  d   QhRR/# r#   r!   )r   rW   s   "€r   r   rX   5  s   ø€ ÷  ñ  ˜4ñ  r   c                óº   € V P                   '       d   R# \        P                  ! 4       pVP                  \        P
                  V P                  4       RV n         R# )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.

Availability: Unix
NT)Ú_initializedÚasyncioÚget_event_loopÚadd_signal_handlerÚsignalÚSIGCHLDÚ_cleanup©ÚclsÚloops   & r   r~   ÚSubprocess.initialize4  sA   € ð ××ÐÙÜ×%Ò%Ó'ˆØ×Ñ¤§¡°·±Ô=ØˆÖr   c                ó   <€ V ^8„  d   QhRR/# r#   r!   )r   rW   s   "€r   r   rX   J  s   ø€ ÷ !ñ !˜Tñ !r   c                ó¤   € V P                   '       g   R# \        P                  ! 4       pVP                  \        P
                  4       RV n         R# )z Removes the ``SIGCHLD`` handler.NF)r“   r”   r•   Úremove_signal_handlerr—   r˜   rš   s   & r   ÚuninitializeÚSubprocess.uninitializeI  s;   € ð ××ÐÙÜ×%Ò%Ó'ˆØ×"Ñ"¤6§>¡>Ô2Ø ˆÖr   c                ó   <€ V ^8„  d   QhRR/# r#   r!   )r   rW   s   "€r   r   rX   S  s   ø€ ÷ *ñ *˜ñ *r   c                ó|   € \        V P                  P                  4       4       F  pV P                  V4       K  	  R # ©N)Úlistr   Úkeysr€   )r›   r:   s   & r   r™   ÚSubprocess._cleanupR  s,   € ä˜Ÿ™×)Ñ)Ó+Ö,ˆCØ×$Ñ$ SÖ)ó -r   c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   r:   r   Nr   )r   rW   s   "€r   r   rX   X  s   ø€ ÷ 	Fñ 	F¡sð 	F¨tñ 	Fr   c                ó  €  \         P                  ! V\         P                  4      w  r#T^ 8X  d   R # Y!8X  g   Q hT P                  P                  T4      pTP                  P                  TP                  T4       R #   \         d     R # i ; ir¥   )	r   ÚwaitpidÚWNOHANGÚChildProcessErrorr   rC   r_   Úadd_callbackÚ_set_returncode)r›   r:   Úret_pidrL   Úsubprocs   &&   r   r€   ÚSubprocess._try_cleanup_processW  su   € ð	Ü Ÿjšj¨¬b¯j©jÓ9‰OˆGð �aŒ<ÙØŒ~Ðˆ~Ø—,‘,×"Ñ" 3Ó'ˆØ�‰×$Ñ$ W×%<Ñ%<¸fÖEøô !ô 	Úð	ús   ‚'A= Á=BÂBc                ó$   <€ V ^8„  d   QhRS[ RR/# )r   rL   r   Nr   )r   rW   s   "€r   r   rX   c  s   ø€ ÷ &ñ &¡cð &¨dñ &r   c                óÌ  € \         P                  R 8X  d	   RV n        Mr\        P                  ! V4      '       d   \        P
                  ! V4      ) V n        M9\        P                  ! V4      '       g   Q h\        P                  ! V4      V n        V P                  V P                  n        V P                  '       d(   V P                  pRV n	        V! V P                  4       R# R# )r2   Néÿÿÿÿ)
r&   r>   rm   r   rD   rF   Ú	WIFEXITEDrG   rg   rl   )rn   rL   r|   s   && r   r¯   ÚSubprocess._set_returncodec  sž   € Ü�<‰<˜7Ô"Ø ˆD�Oä�~Š~˜f×%Ò%Ü#%§;¢;¨vÓ#6Ð"6�•ä—|’| F×+Ò+Ð+Ð+Ü"$§.¢.°Ó"8�”ð  $Ÿ™ˆ�	‰	ÔØ××ÐØ×*Ñ*ˆHØ"&ˆDÔÙ�T—_‘_Ö%ñ r   )rl   r_   r:   rg   rm   r\   rZ   r[   N)T)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Úobjectra   r“   r   ry   r�   r�   Úclassmethodr~   r¡   r™   r€   r¯   Ú__static_attributes__Ú__classdictcell__)rW   s   @r   rS   rS   ¼   s™   ø‡ € ññ* ‹X€Fà€LØ€H÷%ð %÷N2ð 2÷,ò ð@ ÷ ó ð ð( ÷!ó ð!ð ÷*ó ð*ð ÷	Fó ð	F÷&ö &r   rS   r¥   )!r¼   r”   r   r   r—   re   r&   r)   Úbinasciir   Útornado.concurrentr   r   r   Útornador   Útornado.iostreamr   Útornado.logr   Útypingr	   r
   r   ÚTYPE_CHECKINGr   rŒ   r   r,   r9   rN   rQ   rS   r!   r   r   Ú<module>rÈ      sˆ   ðñ ó Û 	Û Û Û Û 
Û å ÷ñ õ
 Ý )Ý ã ß *Ñ *à	××ÐÝð  ×2Ñ2Ð õõ ð €÷]õ@÷w&ó w&r   