3 \# @sdddgZddlZddlZddlZddlZddlmZyejjej Z Wne k rbdZ YnXddZ ddZ dd ZGd ddeZGd d d eZGd ddeZeaejdaea[iZxSsz'BaseProcess.__init__..)AssertionErrornext_process_counterr _identity_configcopyosgetpid _parent_pidr _targettuple_argsdict_kwargstype__name__join_namer _danglingadd)rgrouptargetnameargskwargsrcountrrr__init__Gs    zBaseProcess.__init__cCs|jr|j|j|jdS)zQ Method to be run in sub-process; can be overridden in sub-class N)r#r%r')rrrrrunXszBaseProcess.runcCst|jdkstd|jtjks(tdtjjd s>tdt|j ||_|jj |_ |` |` |`tj|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!rrgetr rsentinel _sentinelr#r%r'r r-)rrrrstart_s   zBaseProcess.startcCs|jjdS)zT Terminate process; sends SIGTERM signal or uses TerminateProcess() N)r terminate)rrrrr:pszBaseProcess.terminatecCsJ|jtjkstd|jdk s(td|jj|}|dk rFtj|dS)z5 Wait until child process terminates zcan only join a child processNzcan only join a started process)r"r r!rr waitr r)rZtimeoutresrrrr*vs  zBaseProcess.joincCsX|tkr dS|jtjks"td|jdkr0dS|jj}|dkrFdStj|dSdS)z1 Return whether process is alive Tzcan only test a child processNF) rr"r r!rr r r r)r returncoderrris_alives   zBaseProcess.is_alivecCs|jS)N)r+)rrrrr0szBaseProcess.namecCst|tstd||_dS)Nzname must be a string) isinstancerrr+)rr0rrrr0scCs|jjddS)z4 Return whether process is a daemon rF)rr6)rrrrrszBaseProcess.daemoncCs |jdkstd||jd<dS)z1 Set whether process is a daemon Nzprocess has already startedr)r rr)rZdaemonicrrrrscCs |jdS)Nauthkey)r)rrrrr@szBaseProcess.authkeycCst||jd<dS)z2 Set authorization key of process r@N)AuthenticationStringr)rr@rrrr@scCs|jdkr|jS|jjS)zM Return exit code of process or `None` if it has yet to stop N)r r )rrrrexitcodes zBaseProcess.exitcodecCs"|tkrtjS|jo|jjSdS)zU Return identifier (PID) of process or `None` if it has yet to start N)rr r!r pid)rrrridentszBaseProcess.identc Cs(y|jStk r"tdYnXdS)z{ Return a file descriptor (Unix) or handle (Windows) suitable for waiting for process termination. zprocess not startedN)r8AttributeError ValueError)rrrrr7szBaseProcess.sentinelcCs|tkrd}n>|jtjkr"d}n*|jdkr2d}n|jjdk rH|j}nd}t|tkrv|dkrfd}ndt j ||}dt|j |j ||j rdpd fS) NZstartedunknowninitialrZstoppedz stopped[%s]z<%s(%s, %s%s)>z daemon)rr"r r!r r rBr(int_exitcode_to_namer6r)r+r)rZstatusrrr__repr__s  zBaseProcess.__repr__c CsJddlm}m}zy||jdk r,|j|jtjdata |j t }|a z|j j |jWd~X|jdz|jd}Wd|jXWntk r}zL|jsd}n:t|jdtr|jd}ntjjt|jddd}WYdd}~Xn2d}ddl}tjjd|j|jYnXWd|jd||jX|S)N)utilcontextz child process calling self.run()r z Process %s: z process exiting with exitcode %d)rIrNrOZ _start_methodZ_force_start_method itertoolsr3rsetr Z _close_stdinrZ_finalizer_registryclearZ_run_after_forkersinfor5Z_exit_function SystemExitr1r?rJsysstderrwriter tracebackr0 print_excZ_flush_std_streams)rrNrOZ old_processrBerYrrr _bootstrapsB        zBaseProcess._bootstrap)N)r) __module__ __qualname____doc__rr4r5r9r:r*r>propertyr0setterrr@rBrDrCr7rLr\rrrrr>s*       c@seZdZddZdS)rAcCs,ddlm}|dkrtdtt|ffS)NrM)get_spawning_popenzJPickling an AuthenticationString object is disallowed for security reasons)rOrb TypeErrorrAbytes)rrbrrr __reduce__s   zAuthenticationString.__reduce__N)r)r]r^rerrrrrAsrAc@seZdZddZdS) _MainProcesscCs2f|_d|_d|_d|_ttjddd|_dS)NZ MainProcess z/mp)r@Z semprefix)rr+r"r rAr urandomr)rrrrr4-s  z_MainProcess.__init__N)r)r]r^r4rrrrrf+srfrMZSIG_) __all__r rVsignalrQ _weakrefsetrpathabspathgetcwdZ ORIGINAL_DIROSErrorrrr objectrrdrArfrr3rrRr rKr __dict__itemsr0Zsignumr,rrrr s2     `