a Z^6c@sddlZddlZddlZddlZddlZddlZddlmZddlm Z gdZ dZ dZ dZ dZd Zd Zd Zdad ad dZddZddZddZddZd?ddZddZddZeZddZdd ZeZ e!Z"d!d"Z#d#d$Z$iZ%e!Z&Gd%d&d&e'Z(d@d'd(Z)d)d*Z*d a+eee)e j,e j-fd+d,Z.e/e.Gd-d.d.e'Z0Gd/d0d0ej1Z2ze3d1Z4Wne5yd2Z4Yn0d3d4Z6d5d6Z7d7d8Z8d9d:Z9d;d<Z:d=d>Z;dS)AN)_args_from_interpreter_flags)process) sub_debugdebuginfo sub_warning get_logger log_to_stderr get_temp_dirregister_after_fork is_exitingFinalizeForkAwareThreadLockForkAwareLocalclose_all_fds_exceptSUBDEBUG SUBWARNINGii iimultiprocessingz+[%(levelname)s/%(processName)s] %(message)sFcGtrtjt|g|RdSN)_loggerlogrZmsgargsr,/usr/lib64/python3.9/multiprocessing/util.pyr,rcGrr)rrDEBUGrrrrr0rrcGrr)rrINFOrrrrr4rrcGrr)rrrrrrrr8rrcCsddl}|zdtsj|tadt_ttdrFtt t t n$tj t diftj t difW|n |0tS)z0 Returns logger used by multiprocessing rN unregisterr)loggingZ _acquireLockrZ getLogger LOGGER_NAMEZ propagatehasattratexitr_exit_functionregisterZ _exithandlersZremoveZappendZ _releaseLock)r rrrr<s    rcCsJddl}t}|t}|}|||||rB||dat S)zB Turn on logging and add a handler which prints to stderr rNT) r rZ FormatterDEFAULT_LOGGING_FORMATZ StreamHandlerZ setFormatterZ addHandlerZsetLevel_log_to_stderrr)Zlevelr ZloggerZ formatterZhandlerrrrr Ws    r cCs tjdkrdSttdrdSdS)NZlinuxTZgetandroidapilevelF)sysZplatformr"rrrr#_platform_supports_abstract_socketsls   r)cCs@|sdSt|tr|ddkSt|tr4|ddkStddS)NFrzz(address type of {address!r} unrecognized) isinstanceZbytesstr TypeError)Zaddressrrris_abstract_socket_namespacets    r-cCs&||t}|dur"d|jd<dS)Ntempdir)rcurrent_process_config)rmtreer.r/rrr_remove_temp_dirsr2cCsftjd}|durbddl}ddl}|jdd}td|tdt |j |fdd|tjd<|S)Nr.rzpymp-)Zprefixzcreated temp directory %si)r exitpriority) rr/r0getshutiltempfileZmkdtemprr r2r1)r.r5r6rrrr s  r c Cshtt}||D]J\\}}}}z ||Wqty`}ztd|WYd}~qd}~00qdS)Nz after forker raised exception %s)list_afterfork_registryitemssort Exceptionr)r9ZindexZidentfuncobjZerrr_run_after_forkerss  r>cCs|tttt||f<dSr)r8next_afterfork_counterZid)r=r<rrrr r c@sFeZdZdZdddZdeeejfddZ dd Z d d Z d d Z dS)r zA Class which supports object finalization using weakrefs rNcCs|dur&t|ts&td|t||dur>t|||_n|durNtd||_ ||_ |p`i|_ |t t f|_t|_|t|j<dS)Nz3Exitpriority ({0!r}) must be None or int, not {1!s}z+Without object, exitpriority cannot be None)r*intr,ZformattypeweakrefZref_weakref ValueError _callback_args_kwargsr?_finalizer_counter_keyosgetpid_pid_finalizer_registry)selfr=ZcallbackrZkwargsr3rrr__init__s   zFinalize.__init__cCsz ||j=Wnty&|dYnf0|j|krB|dd}n(|d|j|j|j|j|ji|j}d|_|_|_|_|_|SdS)zQ Run the callback unless it has already been called or cancelled zfinalizer no longer registeredz+finalizer ignored because different processNz/finalizer calling %s with args %s and kwargs %s)rKKeyErrorrNrGrHrIrE)rPZwrrOrrMZresrrr__call__s    zFinalize.__call__cCsBz t|j=WntyYn 0d|_|_|_|_|_dS)z3 Cancel finalization of the object N)rOrKrRrErGrHrIrPrrrcancels  zFinalize.cancelcCs |jtvS)zS Return whether this finalizer is still waiting to invoke callback )rKrOrTrrr still_activezFinalize.still_activec Csz |}Wnttfy&d}Yn0|durz<%s object, callback=%s__name__z, args=z , kwargs=rz, exitpriority=z>) rEAttributeErrorr,Z __class__rXZgetattrrGrHr+rIrK)rPr=Zxrrr__repr__s"   zFinalize.__repr__)rNN) rX __module__ __qualname__Z__doc__rQrOrrLrMrSrUrVrZrrrrr s   r c stdur dSdurddn fddfddttD}|jdd|D]N}t|}|durPtd |z |WqPtyd dl}|YqP0qPdurtdS) z Run all finalizers whose exit priority is not None and at least minpriority Finalizers with highest priority are called first; finalizers with the same priority will be called in reverse order of creation. NcSs |dduSNrrprrrz!_run_finalizers..cs|dduo|dkSr]rr^) minpriorityrrr`racsg|]}|r|qSrr)Z.0key)frrZ #raz#_run_finalizers..T)Zreversez calling %sr) rOr7r:r4rr; tracebackZ print_excclear)rbZkeysrcZ finalizerrer)rdrbr_run_finalizers s$       rgcCs tp tduS)z6 Returns true if the process is shutting down N)_exitingrrrrr 8rWr cCstsda|d|d|d|durr|D] }|jr0|d|j|jq0|D]}|d|j|qX|d|dS)NTzprocess shutting downz2running all "atexit" finalizers with priority >= 0rz!calling terminate() for daemon %szcalling join() for process %sz)running the remaining "atexit" finalizers)rhZdaemonZnameZ_popenZ terminateZjoin)rrrgactive_childrenr/r_rrrr$@s        r$c@s,eZdZddZddZddZddZd S) rcCs.t|_|jj|_|jj|_t|tjdSr) threadingZLock_lockZacquireZreleaser r_at_fork_reinitrTrrrrQqs   zForkAwareThreadLock.__init__cCs|jdSr)rkrlrTrrrrlwrAz#ForkAwareThreadLock._at_fork_reinitcC |jSr)rk __enter__rTrrrrnzrAzForkAwareThreadLock.__enter__cGs |jj|Sr)rk__exit__)rPrrrrro}rAzForkAwareThreadLock.__exit__N)rXr[r\rQrlrnrorrrrrpsrc@seZdZddZddZdS)rcCst|dddS)NcSrmr)Z__dict__rf)r=rrrr`raz)ForkAwareLocal.__init__..)r rTrrrrQrAzForkAwareLocal.__init__cCs t|dfS)Nr)rCrTrrr __reduce__rAzForkAwareLocal.__reduce__N)rXr[r\rQrprrrrrsrZ SC_OPEN_MAXicCsNt|dtg}|tt|dD] }t||d||dq(dS)Nr)r7MAXFDr:ZrangeZlenrLZ closerange)fdsZirrrrsrc CstjdurdSztjWnttfy2Yn0z@ttjtj}zt|ddt_Wnt|Yn0WnttfyYn0dS)NF)Zclosefd) r(ZstdincloseZOSErrorrFrLZopenZdevnullZO_RDONLY)fdrrr _close_stdins   rvc CsPztjWnttfy$Yn0ztjWnttfyJYn0dSr)r(ZstdoutZflushrYrFZstderrrrrr_flush_std_streamssrwcCsddl}tttt|}t\}}zP||t|gd|dddddddd||dddddddWt |t |St |t |0dS)NrTrqF) _posixsubprocessZtupleZsortedZmaprBrLZpipeZ fork_execZfsencodert)ZpathrZpassfdsrxZ errpipe_readZ errpipe_writerrrspawnv_passfdss     rycGs|D]}t|qdS)z/Close each file descriptor given as an argumentN)rLrt)rsrurrr close_fdssrzcCsZddlm}tddlm}|jddlm}|j t | | dS)zKCleanup multiprocessing resources when multiprocessing tests completed.r)support) forkserver)resource_trackerN) Ztestr{rZ_cleanuprr|Z _forkserverZ_stopr}Z_resource_trackerrgZ gc_collectZ reap_children)r{r|r}rrr_cleanup_testss     r~rr)r rOrJZobjectr rgr rhrir/r$r%rZlocalrZsysconfrrr;rrvrwryrzr~rrrrZ sn       V , *