a ;`.@s2gdZddlZddlZddlZddlZddlZddlmZzej e Z Wne yfdZ Yn0ddZ ddZdd Zd d ZGd d d eZGdddeZGdddeZGdddeZdaeaedaea[iZeej D]0\Z!Z"e!dddkrde!vrde!ee" <qeZ#dS)) BaseProcesscurrent_processactive_childrenparent_processN)WeakSetcCstS)z@ Return process object representing the current process )_current_processrr-/usr/lib/python3.9/multiprocessing/process.pyr%srcCstttS)zN Return list of process objects corresponding to live child processes )_cleanuplist _childrenrrrr r+srcCstS)z? Return process object representing the parent process )_parent_processrrrr r3srcCs*ttD]}|jdurt|qdSN)r r _popenpolldiscard)prrr r =s r c@seZdZdZddZddddifddddZd d Zd d Zd dZddZ ddZ d,ddZ ddZ ddZ eddZejddZeddZejddZedd Zejd!d Zed"d#Zed$d%ZeZed&d'Zd(d)Zd-d*d+ZdS).rz Process objects represent activity that is run in a separate process The class is analogous to `threading.Thread` cCstdSr)NotImplementedErrorselfrrr _PopenMszBaseProcess._PopenNr)daemoncCs|dusJdtt}tj|f|_tj|_t|_tj |_ d|_ d|_ ||_ t||_t||_|pt|jdddd|jD|_|dur||_t|dS)Nz#group argument must be None for nowF-:css|]}t|VqdSr)str).0irrr ^z'BaseProcess.__init__..)next_process_counterr _identity_configcopyosgetpid _parent_pidname _parent_namer_closed_targettuple_argsdict_kwargstype__name__join_namer _danglingadd)rgrouptargetr'argskwargsrcountrrr __init__Ps"    zBaseProcess.__init__cCs|jrtddS)Nzprocess object is closed)r) ValueErrorrrrr _check_closedcszBaseProcess._check_closedcCs|jr|j|ji|jdS)zQ Method to be run in sub-process; can be overridden in sub-class N)r*r,r.rrrr rungszBaseProcess.runcCsz||jdusJd|jtks0JdtjdrDJdt| ||_|jj |_ |` |` |`t|dS)z% Start child process Nzcannot start a process twicez:can only start a process object created by current processrz3daemonic processes are not allowed to have children)r<rr&r$r%rr"getr rsentinel _sentinelr*r,r.r r4rrrr startns   zBaseProcess.startcCs||jdS)zT Terminate process; sends SIGTERM signal or uses TerminateProcess() N)r<r terminaterrrr rBszBaseProcess.terminatecCs||jdS)zT Terminate process; sends SIGKILL signal or uses TerminateProcess() N)r<rkillrrrr rCszBaseProcess.killcCsR||jtksJd|jdus0Jd|j|}|durNt|dS)z5 Wait until child process terminates zcan only join a child processNzcan only join a started process)r<r&r$r%rwaitr r)rtimeoutresrrr r1s  zBaseProcess.joincCs`||turdS|jtks*Jd|jdur8dS|j}|durNdSt|dSdS)z1 Return whether process is alive Tzcan only test a child processNF) r<rr&r$r%rrr r)r returncoderrr is_alives   zBaseProcess.is_alivecCsH|jdur>|jdur td|jd|_|`t|d|_dS)z Close the Process object. This method releases resources held by the Process object. It is an error to call this method if the child process is still running. Nz^Cannot close a process while it is still running. You should first call join() or terminate().T)rrr;closer@r rr)rrrr rIs   zBaseProcess.closecCs|jSr)r2rrrr r'szBaseProcess.namecCst|tsJd||_dS)Nzname must be a string) isinstancerr2)rr'rrr r'scCs|jddS)z4 Return whether process is a daemon rF)r"r>rrrr rszBaseProcess.daemoncCs |jdusJd||jd<dS)z1 Set whether process is a daemon Nzprocess has already startedr)rr")rZdaemonicrrr rscCs |jdS)Nauthkey)r"rrrr rKszBaseProcess.authkeycCst||jd<dS)z2 Set authorization key of process rKN)AuthenticationStringr")rrKrrr rKscCs"||jdur|jS|jS)zM Return exit code of process or `None` if it has yet to stop N)r<rrrrrr exitcodes zBaseProcess.exitcodecCs*||turtS|jo$|jjSdS)zU Return identifier (PID) of process or `None` if it has yet to start N)r<rr$r%rpidrrrr identszBaseProcess.identcCs2|z|jWSty,tddYn0dS)z{ Return a file descriptor (Unix) or handle (Windows) suitable for waiting for process termination. zprocess not startedN)r<r@AttributeErrorr;rrrr r?s  zBaseProcess.sentinelcCsd}|turd}nL|jrd}n@|jtkr2d}n,|jdurBd}n|j}|durZd}nd}t|jd|j g}|jdur| d|jj | d|j| ||durt ||}| d ||jr| d d d |S) NZstartedclosedunknowninitialZstoppedzname=%rzpid=%sz parent=%sz exitcode=%srz<%s> )rr)r&r$r%rrr/r0r2appendrN_exitcode_to_namer>rr1)rrMZstatusinforrr __repr__s0      zBaseProcess.__repr__c Csddlm}m}z`z|jdur,||jtdata | t }|a t |j |j|atjrntz|j|W~n~0|dz|d}W|n |0Wnty }zJ|jdurd}n.t|jtr|j}ntj t!|jdd}WYd}~n:d}~0d}ddl"}tj d|j#|$Yn0Wt%|d||&n t%|d||&0|S)N)utilcontextz child process calling self.run()r z Process %s: z process exiting with exitcode %d)'rZr[Z _start_methodZ_force_start_method itertoolsr9r setr Z _close_stdinr_ParentProcessr(r&r threadingZ_HAVE_THREAD_NATIVE_IDZ main_threadZ_set_native_idZ_finalizer_registryclearZ_run_after_forkersrWr=Z_exit_function SystemExitcoderJintsysstderrwriter tracebackr' print_excZ _shutdownZ_flush_std_streams)rZparent_sentinelrZr[Z old_processrMerirrr _bootstrap"sT            zBaseProcess._bootstrap)N)N)r0 __module__ __qualname____doc__rr:r<r=rArBrCr1rHrIpropertyr'setterrrKrMrOrNr?rXrlrrrr rGsD            rc@seZdZddZdS)rLcCs,ddlm}|durtdtt|ffS)NrY)get_spawning_popenzJPickling an AuthenticationString object is disallowed for security reasons)r[rr TypeErrorrLbytes)rrrrrr __reduce__Xs   zAuthenticationString.__reduce__N)r0rmrnrurrrr rLWsrLc@s6eZdZddZddZeddZd dd ZeZdS) r`cCs4d|_||_||_d|_d|_d|_||_i|_dS)NrF)r!r2_pidr&rr)r@r")rr'rNr?rrr r:hsz_ParentProcess.__init__cCsddlm}||jgdd S)NrrDrEZmultiprocessing.connectionrDr@)rrDrrr rHrs z_ParentProcess.is_alivecCs|jSr)rvrrrr rOvsz_ParentProcess.identNcCs ddlm}||jg|ddS)z6 Wait until parent process terminates rrwrxNry)rrErDrrr r1zs z_ParentProcess.join)N) r0rmrnr:rHrprOr1rNrrrr r`fs    r`c@seZdZddZddZdS) _MainProcesscCs8d|_d|_d|_d|_d|_ttddd|_dS)NrZ MainProcessF z/mp)rKZ semprefix) r!r2r&rr)rLr$urandomr"rrrr r:s z_MainProcess.__init__cCsdSrrrrrr rIsz_MainProcess.closeN)r0rmrnr:rIrrrr rzsrzrYZSIG_r)$__all__r$rfsignalr^raZ _weakrefsetrpathabspathgetcwdZ ORIGINAL_DIROSErrorrrrr objectrrtrLr`rzr rr9r r_r rVr __dict__itemsr'Zsignumr3rrrr  s<     !