L ih6VddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z m Z ddl mZddlmZmZddlmZdZej*eZgdZGd d eZGd d eZGd deZdZGddZGddeZ ddeefdZ ddZ!y)N) as_completedThreadPoolExecutor)Optional)6maybe_temporarily_apply_numa_binding_to_current_thread NumaOptions)_prctl_pr_set_pdeathsigTORCH_MP_PARALLEL_START)ProcessContextProcessExceptionProcessExitedExceptionProcessRaisedExceptionspawn SpawnContextstart_processesc:eZdZddgZdededeffd ZdZxZS)r error_index error_pidmsgpidcNt||||_||_||_yN)super__init__rrr)selfrrr __class__s a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/multiprocessing/spawn.pyrzProcessException.__init__)s& &c^t||j|j|jffSr)typerrrrs r __reduce__zProcessException.__reduce__/s&DzDHHd&6&6AAAr) __name__ __module__ __qualname__ __slots__strintrr" __classcell__rs@rr r &s- ,ICc Brr c0eZdZdZdededeffd ZxZS)rzNException raised when a process failed due to an exception raised by the code.rrrc(t||||yr)rr)rrrrrs rrzProcessRaisedException.__init__6s k95r)r#r$r%__doc__r'r(rr)r*s@rrr3s,X6 66 66rrc NeZdZdZdgZ d dededededeef fd ZdZ xZ S) r zTException raised when a process failed due to signal or exited with a specific code. exit_coderrr signal_namecDt||||||_||_yr)rrr/r0)rrrrr/r0rs rrzProcessExitedException.__init__Ds% k95"&rct||j|j|j|j|j ffSr)r rrrr/r0r!s rr"z!ProcessExitedException.__reduce__Ps9 J XXt''4>>4CSCS T  rr) r#r$r%r-r&r'r(rrr"r)r*s@rr r ?sP^ I&* '  ' ' '  ' c] ' rr c:ttj ||g|y#t$rYyt$rbddl}t |d5}tj|j|dddn #1swYnxYwtjdYywxYw)Nrwbr) r signalSIGINTKeyboardInterrupt Exception tracebackopenpickledump format_excsysexit)fniargs error_filer9fhs r_wraprEWs FMM*  1 t    *d # 4r KK ,,. 3 4 4 4  s, % BB%A6- B6A? ;BBcDeZdZdZdZdefdZ ddeedeefdZy) r c||_||_t|Dcic]\}}|j|c}}|_ycc}}wr) error_files processes enumeratesentinel sentinels)rrIrHindexprocesss rrzProcessContext.__init__lsA&":CI:N (6wG  e #  s>cf|jDcgc]}t|jc}Scc}wr)rIr(r)rrNs rpidszProcessContext.pidsss#04?WGKK ???s.timeoutctj|z}|jD]4}td|tjz }|j |6y)z4Attempt to join all processes with a shared timeout.rN)time monotonicrImaxjoin)rrQendrN time_to_waits r_join_procs_with_timeoutz'ProcessContext._join_procs_with_timeoutvsJnn(~~ 'Gq#(8"89L LL & 'rN grace_periodct|jdk(rytjj |jj |}d}|D]O}|jj |}|j|}|j|jdk7sM|}n|t|jdk(S||j||jD]C}|jstjd|j|jE|j|dn||jD]R}|jr0tjd|j|j!|jT|j|}t#j$|j&|t"j(s|j|j} | dkrB t+j,| j.} t3d |d d | ||j| | t3d |d d| d ||j| t5|j&|d5} t7j8| } dddd|d d} |  z } t;| ||j#t0$r d| d } YwxYw#1swYBxYw)aLJoin 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. rT)rQNz)Terminating process %s via signal SIGTERMzJUnable to shutdown process %s via SIGTERM , forcefully exiting via SIGKILLzzprocess dz terminated with signal )rrr/r0z terminated with exit code )rrr/rbz -- Process z& terminated with the following error: )lenrLmultiprocessing connectionwaitkeyspoprIrVexitcoderYis_alivelogwarningr terminatekillosaccessrHR_OKr5Signalsname ValueErrorr r:r;loadr)rrQrZreadyrrKrMrNfailed_processrfrprDoriginal_tracers rrVzProcessContext.join}s( t~~ ! # **// NN   !0    HNN&&x0EnnU+G LLN1$#     t~~&!+ +  #  ) ), 7~~ $G! GU!!# $ %%L,@blS~~ G! `KK  LLN  4yy))+6@~~k2;;H!|;!>>8)499D-{1o-EdVL +,00& $ -{1o-HRS U +,00& $"";/ 6 -"#[[_N - A.UV ~$S+~7I7IJJ+";-xi[:D;" - -s= J98K9K  K K)NN) r#r$r%rrPfloatrYrrVrrr r ksC @''PT_K_K=Ee__Krr ceZdZfdZxZS)rcPtjdt| ||y)Nz.start_processs ( (' %    "''**arww' &Dl   MMO '277""   s <B$$B-) max_workers)rlenvirongetENV_VAR_PARALLEL_STARTrhinfora get_contextrangersubmitrresultr rV)r@rBnprocsrVr start_methodr|start_parallelrHrIrrAidxrNtf_nameexecutorfuturesfutcontextrs`` ` ` @rrrs\  $ JJNN13 73 > 23  $ $\ 2B&6/KI$#$#L v %A$1!$4 !C'&K $IcN %  F 3 )xBG-PQx}a8PGP#G, )(+ %Wg#* C !( #  ) )Y 4G lln llnQ ) )s+E9D?0E?EE cr|dk7r"d|d}tj|tdt|||||dS)aSpawns ``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`` rz3This method only supports start_method=spawn (got: zU). To use a different start_method use: torch.multiprocessing.start_processes(...)) stacklevel)r)rzr{ FutureWarningr)r@rBrrVrrrs rrrDsKBwA,P: :  c=Q7 2tVT6 PPr)rwrTFrN)rwrTFr)"loggingramultiprocessing.connectionrlr;r5r>rrSrzconcurrent.futuresrrtypingrtorch.numa.bindingrrr r getLoggerr#rh__all__r8r rr rEr rrrrwrrrs!  ? &3g!  By B 6- 6 - 0(qKqKh1>1 *.T ;'T n(Qr