U e5d.@s8ddddgZddlZddlZddlZddlZddlZddlmZzej e Z Wne k rldZ YnXddZ ddZd dZd d ZGd ddeZGd ddeZGdddeZGdddeZdaeaedaea[iZeej D]0\Z!Z"e!dddkrde!krde!ee" <qeZ#dS) BaseProcesscurrent_processactive_childrenparent_processN)WeakSetcCstS)z@ Return process object representing the current process )_current_processrr//usr/lib64/python3.8/multiprocessing/process.pyr%scCstttS)zN Return list of process objects corresponding to live child processes )_cleanuplist _childrenrrrr r+scCstS)z? Return process object representing the parent process )_parent_processrrrr r3scCs*ttD]}|jdk rt|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|dkstdtt}tj|f|_tj|_t|_ tj |_ d|_ d|_ ||_t||_t||_|pt|jdddd|jD|_|dk r||_t|dS)Nz#group argument must be None for nowF-:css|]}t|VqdSr)str).0irrr ^sz'BaseProcess.__init__..)AssertionErrornext_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|j|jdS)zQ Method to be run in sub-process; can be overridden in sub-class N)r*r,r.rrrr rungszBaseProcess.runcCsz||jdkstd|jtks0tdtjdrDtdt | ||_|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<rrr&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||jtkstd|jdk s0td|j|}|dk rNt|dS)z5 Wait until child process terminates zcan only join a child processNzcan only join a started process) r<r&r$r%rrwaitr r)rtimeoutresrrr r1s  zBaseProcess.joincCs`||tkrdS|jtks*td|jdkr8dS|j}|dkrNdSt |dSdS)z1 Return whether process is alive Tzcan only test a child processNF) r<rr&r$r%rrrr r)r returncoderrr is_alives   zBaseProcess.is_alivecCsH|jdk r>|jdkr 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|tstd||_dS)Nzname must be a string) isinstancerrr2)rr'rrr r'scCs|jddS)z4 Return whether process is a daemon rF)r"r>rrrr rszBaseProcess.daemoncCs |jdkstd||jd<dS)z1 Set whether process is a daemon Nzprocess has already startedr)rrr")rZdaemonicrrr rscCs |jdS)Nauthkey)r"rrrr rKszBaseProcess.authkeycCst||jd<dS)z2 Set authorization key of process rKN)AuthenticationStringr")rrKrrr rKscCs"||jdkr|jS|jS)zM Return exit code of process or `None` if it has yet to stop N)r<rrrrrr exitcodes zBaseProcess.exitcodecCs*||tkrtS|jo$|jjSdS)zU Return identifier (PID) of process or `None` if it has yet to start N)r<rr$r%rpidrrrr identszBaseProcess.identcCs4|z|jWStk r.tddYnXdS)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}|tkrd}nL|jrd}n@|jtkr2d}n,|jdkrBd}n|j}|dk rZd}nd}t|jd|j g}|jdk r| d|jj | d|j| ||dk rt ||}| 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 Csvddlm}m}z>z|jdk r,||jt da t a |t}|at|j|j|atjrntz|j|W5~X|dz|d}W5|XWntk r}zJ|jsd}n:t|jdtr|jd}nt j!"t#|jddd}W5d}~XYn2d}ddl$}t j!"d|j%|&YnXW5t|d||X|S)N)utilcontextz process exiting with exitcode %dz child process calling self.run()r z Process %s: )'rZr[ threadingZ _shutdownrWZ_flush_std_streamsZ _start_methodZ_force_start_method itertoolsr9r setr Z _close_stdinr_ParentProcessr(r&r Z_HAVE_THREAD_NATIVE_IDZ main_threadZ_set_native_idZ_finalizer_registryclearZ_run_after_forkersZ_exit_functionr= SystemExitr7rJintsysstderrwriter tracebackr' print_exc)rZparent_sentinelrZr[rMZ old_processerhrrr _bootstrap"sR         zBaseProcess._bootstrap)N)N)r0 __module__ __qualname____doc__rr:r<r=rArBrCr1rHrIpropertyr'setterrrKrMrOrNr?rXrkrrrr rGsD            c@seZdZddZdS)rLcCs,ddlm}|dkrtdtt|ffS)NrY)get_spawning_popenzJPickling an AuthenticationString object is disallowed for security reasons)r[rq TypeErrorrLbytes)rrqrrr __reduce__Xs   zAuthenticationString.__reduce__N)r0rlrmrtrrrr rLWsrLc@s6eZdZddZddZeddZd dd ZeZdS) racCs4d|_||_||_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)rurrrr rOvsz_ParentProcess.identNcCs ddlm}||jg|ddS)z6 Wait until parent process terminates rrvrwNrx)rrErDrrr r1zs z_ParentProcess.join)N) r0rlrmr:rHrorOr1rNrrrr rafs    rac@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)r0rlrmr:rIrrrr rysryrYZSIG_r)$__all__r$resignalr_r^Z _weakrefsetrpathabspathgetcwdZ ORIGINAL_DIROSErrorrrrr objectrrsrLraryr rr9r r`r rVr __dict__itemsr'Zsignumr3rrrr  s@    !