
    JTh2                     <   S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
JrJr  S SKJr  SSKJr  Sr\ R$                  " \5      r/ SQr " S S	\5      r " S
 S\5      r " S S\5      rS r " S S5      r " S S\5      r     SS jrSS jrg)    N)as_completedThreadPoolExecutor)Optional   )_prctl_pr_set_pdeathsigTORCH_MP_PARALLEL_START)ProcessContextProcessExceptionProcessExitedExceptionProcessRaisedExceptionspawnSpawnContextstart_processesc                   F   ^  \ rS rSrSS/rS\S\S\4U 4S jjrS rSr	U =r
$ )	r
   !   error_index	error_pidmsgpidc                 H   > [         TU ]  U5        Xl        X l        X0l        g N)super__init__r   r   r   )selfr   r   r   	__class__s       S/var/www/auris/envauris/lib/python3.13/site-packages/torch/multiprocessing/spawn.pyr   ProcessException.__init__$   s     &    c                 ^    [        U 5      U R                  U R                  U R                  44$ r   )typer   r   r   r   s    r   
__reduce__ProcessException.__reduce__*   s&    DzDHHd&6&6AAAr   )r   r   r   )__name__
__module____qualname____firstlineno__	__slots__strintr   r"   __static_attributes____classcell__r   s   @r   r
   r
   !   s3    ,IC c  B Br   r
   c                   <   ^  \ rS rSrSrS\S\S\4U 4S jjrSrU =r	$ )r   .   zNException raised when a process failed due to an exception raised by the code.r   r   r   c                 &   > [         TU ]  XU5        g r   )r   r   )r   r   r   r   r   s       r   r   ProcessRaisedException.__init__1   s     	95r    )
r$   r%   r&   r'   __doc__r)   r*   r   r+   r,   r-   s   @r   r   r   .   s,    X66 6 	6 6r   r   c                   \   ^  \ rS rSrSrS/r SS\S\S\S\S\\   4
U 4S jjjr	S	 r
S
rU =r$ )r   :   zTException raised when a process failed due to signal or exited with a specific code.	exit_coder   r   r   signal_namec                 >   > [         TU ]  XU5        X@l        XPl        g r   )r   r   r6   r7   )r   r   r   r   r6   r7   r   s         r   r   ProcessExitedException.__init__?   s     	95"&r   c                     [        U 5      U R                  U R                  U R                  U R                  U R
                  44$ r   )r    r   r   r   r6   r7   r!   s    r   r"   !ProcessExitedException.__reduce__K   s9    JXXt''4>>4CSCST
 	
r   )r6   r7   r   )r$   r%   r&   r'   r3   r(   r)   r*   r   r   r"   r+   r,   r-   s   @r   r   r   :   sZ    ^I &*
'
' 
' 	
'
 
' c]
' 
'
 
r   r   c                 L   [        [        R                  5         U " U/UQ76   g ! [         a     g [         ai    SS Kn[        US5       n[        R                  " UR                  5       U5        S S S 5        O! , (       d  f       O= f[        R                  " S5         g f = f)Nr   wbr   )r   signalSIGINTKeyboardInterrupt	Exception	tracebackopenpickledump
format_excsysexit)fniargs
error_filerB   fhs         r   _wraprN   R   sw    
 FMM*

1t  *d#rKK	,,.3 $##s,   	% 
B#B#
&A90	B#9
B	B#"B#c                   R    \ rS rSrS rS rS\4S jr S
S\\   S\\   4S jjr	S	r
g)r	   f   c                     X l         Xl        [        U5       VVs0 s H  u  p4UR                  U_M     snnU l        g s  snnf r   )error_files	processes	enumeratesentinel	sentinels)r   rS   rR   indexprocesss        r   r   ProcessContext.__init__g   s@    &":CI:N
:NGe#:N
 
s   >c                 l    U R                    Vs/ s H  n[        UR                  5      PM     sn$ s  snf r   )rS   r*   r   )r   rX   s     r   pidsProcessContext.pidsn   s'    04?WGKK ???s   1timeoutc                     [         R                  " 5       U-   nU R                   H6  n[        SU[         R                  " 5       -
  5      nUR	                  U5        M8     g)z4Attempt to join all processes with a shared timeout.r   N)time	monotonicrS   maxjoin)r   r]   endrX   time_to_waits        r   _join_procs_with_timeout'ProcessContext._join_procs_with_timeoutq   sE    nn(~~Gq#(8"89LLL& &r   Ngrace_periodc                    [        U R                  5      S:X  a  g[        R                  R	                  U R                  R                  5       US9nSnU HQ  nU R                  R                  U5      nU R                  U   nUR                  5         UR                  S:w  d  MO  Un  O   Uc  [        U R                  5      S:H  $ Ub  U R                  U5        U R                   HJ  nUR                  5       (       d  M  [        R                  SUR                  5        UR                  5         ML     U R                  Uc  SOU5        U R                   HX  nUR                  5       (       a0  [        R                  SUR                  5        UR!                  5         UR                  5         MZ     U R                  U   n["        R$                  " U R&                  U   ["        R(                  5      (       d}  U R                  U   R                  n	U	S:  a@   [*        R,                  " U	* 5      R.                  n
[3        S
US SU
 3UUR                  U	U
S9e[3        S
US SU	S 3UUR                  U	S9e[5        U R&                  U   S5       n[6        R8                  " U5      nSSS5        SUS S3nUW-  n[;        XUR                  5      e! [0         a
    SU	*  S	3n
 Nf = f! , (       d  f       NG= f)a  Join one or more processes within spawn context.

Attempt to join one or more processes in this spawn context.
If one of them exited with a non-zero exit status, this function
kills the remaining processes (optionally with a grace period)
and raises an exception with the cause of the first process exiting.

Returns ``True`` if all processes have been joined successfully,
``False`` if there are more processes that need to be joined.

Args:
    timeout (float): Wait this long (in seconds) before giving up on waiting.
    grace_period (float): When any processes fail, wait this long (in seconds)
        for others to shutdown gracefully before terminating them. If they
        still don't exit, wait another grace period before killing them.
r   T)r]   Nz)Terminating process %s via signal SIGTERM   zJUnable to shutdown process %s via SIGTERM , forcefully exiting via SIGKILLz<Unknown signal >zprocess dz terminated with signal )r   r   r6   r7   z terminated with exit code )r   r   r6   rbz

-- Process z& terminated with the following error:
)lenrV   multiprocessing
connectionwaitkeyspoprS   rb   exitcodere   is_alivelogwarningr   	terminatekillosaccessrR   R_OKr>   Signalsname
ValueErrorr   rC   rD   loadr   )r   r]   rg   readyr   rU   rW   rX   failed_processrs   r}   rM   original_tracer   s                 r   rb   ProcessContext.joinx   s   ( t~~!#  **//NN! 0 

 HNN&&x0EnnU+GLLN1$#  t~~&!++ #)),7~~G!!GU!!# & 	%%L,@blS~~G!!`KK LLN & 4yy))+6@@~~k2;;H!|;!>>8)499D -{1o-EdVL +,00& $  -{1o-HRSU +,00&	  $"";/6"#[[_N 7A.UV~$S~7I7IJJ+ " ;-xi[:D;" 76s   !K K%K"!K"%
K3)rR   rS   rV   )NN)r$   r%   r&   r'   r   r[   floatre   r   rb   r+   r2   r   r   r	   r	   f   sJ    
@' ' PT_K_K=Ee__K _Kr   r	   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )r      c                 P   > [         R                  " S5        [        TU ]  X5        g )Nz<SpawnContext is renamed to ProcessContext since 1.4 release.)warningswarnr   r   )r   rS   rR   r   s      r   r   SpawnContext.__init__   s    TU0r   r2   )r$   r%   r&   r'   r   r+   r,   r-   s   @r   r   r      s    1 1r   r   c                   ^ ^^^ US:X  a@  [         R                  R                  [        S5      S:X  a  [        R                  S5        SnOSn[        R                  " U5      mS /U-  nS /U-  nUUU U4S jn	U(       d&  [        U5       H  n
U	" U
5      u  pnXU'   XU'   M     Oh[        US9 n[        U5       V
s/ s H  oR                  X5      PM     nn
[        U5       H  nUR                  5       u  pnXU'   XU'   M      S S S 5        [        X5      nU(       d  U$ UR                  5       (       d   UR                  5       (       d  M  g g s  sn
f ! , (       d  f       NV= f)	N
forkserver01zStarting processes in parallel.TFc                   > [         R                  " SSSS9nUR                  5         [        R                  " UR
                  5        TR                  [        TU TUR
                  4TS9nUR                  5         XUR
                  4$ )Nzpytorch-errorfile-z.pickleF)prefixsuffixdelete)targetrK   daemon)	tempfileNamedTemporaryFileclosery   unlinkr}   ProcessrN   start)rJ   tfrX   rK   r   rI   mps      r   start_process&start_processes.<locals>.start_process  sz     (('	%
 	

		"''**arww'  

 	277""r   )max_workers)ry   environgetENV_VAR_PARALLEL_STARTru   inforn   get_contextranger   submitr   resultr	   rb   )rI   rK   nprocsrb   r   start_methodstart_parallelrR   rS   r   rJ   idxrX   tf_nameexecutorfuturesfutcontextr   s   ``  `             @r   r   r      s=    	$JJNN1373>23 		$	$\	2B&6/KI# #( vA$1!$4!C'&$cN 
  F3xBG-P-Q}8-GP#G,(+

%g#*C !(#	 - 4 Y4G llnn llnn Q 43s   .E<E/EE
E#c           	      f    US:w  a   SU S3n[         R                  " U[        SS9  [        XX#USS9$ )aR  Spawns ``nprocs`` processes that run ``fn`` with ``args``.

If one of the processes exits with a non-zero exit status, the
remaining processes are killed and an exception is raised with the
cause of termination. In the case an exception was caught in the
child process, it is forwarded and its traceback is included in
the exception raised in the parent process.

Args:
    fn (function): Function is called as the entrypoint of the
        spawned process. This function must be defined at the top
        level of a module so it can be pickled and spawned. This
        is a requirement imposed by multiprocessing.

        The function is called as ``fn(i, *args)``, where ``i`` is
        the process index and ``args`` is the passed through tuple
        of arguments.

    args (tuple): Arguments passed to ``fn``.
    nprocs (int): Number of processes to spawn.
    join (bool): Perform a blocking join on all processes.
    daemon (bool): The spawned processes' daemon flag. If set to True,
                   daemonic processes will be created.
    start_method (str): (deprecated) this method will always use ``spawn``
                           as the start method. To use a different start method
                           use ``start_processes()``.

Returns:
    None if ``join`` is ``True``,
    :class:`~ProcessContext` if ``join`` is ``False``

r   z3This method only supports start_method=spawn (got: zU).
To use a different start_method use:
		 torch.multiprocessing.start_processes(...)   )
stacklevel)r   )r   r   FutureWarningr   )rI   rK   r   rb   r   r   r   s          r   r   r   ,  sG    B wA, P: : 	
 	c=Q72V6PPr   )r2   r   TFr   )loggingrn   multiprocessing.connectionry   rD   r>   rG   r   r_   r   concurrent.futuresr   r   typingr    r   r   	getLoggerr$   ru   __all__rA   r
   r   r   rN   r	   r   r   r   r2   r   r   <module>r      s      ! 	   
    ?  % 3 !
By 
B	6- 	6
- 
0(qK qKh1> 1  
	AH(Qr   