U e5d~6@sddlZddlZddlZddlZddlZddlZddlmZddlm Z ddddd d d d d ddddddgZ dZ dZ dZ dZdZdZdZdadaddZddZddZddZdd Zd@d d Zd!d"Zd#d$ZeZd%d&Zd'd ZeZ e!Z"d(d)Z#d*d Z$iZ%e!Z&Gd+dde'Z(dAd,d-Z)d.d Z*da+eee)e j,e j-fd/d0Z.e/e.Gd1dde'Z0Gd2ddej1Z2ze3d3Z4Wne5k rd4Z4YnXd5dZ6d6d7Z7d8d9Z8d:d;Z9dd?Z;dS)BN)_args_from_interpreter_flags)process sub_debugdebuginfo sub_warning get_logger log_to_stderr get_temp_dirregister_after_fork is_exitingFinalizeForkAwareThreadLockForkAwareLocalclose_all_fds_exceptSUBDEBUG SUBWARNING multiprocessingz+[%(levelname)s/%(processName)s] %(message)sFcGstrtjt|f|dSN)_loggerlogrmsgargsr,/usr/lib64/python3.8/multiprocessing/util.pyr,scGstrtjt|f|dSr)rrDEBUGrrrr r0scGstrtjt|f|dSr)rrINFOrrrr r4scGstrtjt|f|dSr)rrrrrrr r8scCs|ddl}|z\tsj|tadt_ttdrFt t t t n$tj t diftj t difW5|XtS)z0 Returns logger used by multiprocessing rN unregisterr)loggingZ _acquireLockZ _releaseLockrZ getLogger LOGGER_NAMEZ propagatehasattratexitr#_exit_functionregisterZ _exithandlersremoveappend)r$rrr r <s     cCsJddl}t}|t}|}|||||rB||dat S)zB Turn on logging and add a handler which prints to stderr rNT) r$r Z FormatterDEFAULT_LOGGING_FORMATZ StreamHandlerZ setFormatterZ addHandlerZsetLevel_log_to_stderrr)levelr$ZloggerZ formatterZhandlerrrr r Ws    cCs tjdkrdSttdrdSdS)NZlinuxTZgetandroidapilevelF)sysplatformr&rrrr #_platform_supports_abstract_socketsls   r1cCs@|sdSt|tr|ddkSt|tr4|ddkStddS)NFrz(address type of {address!r} unrecognized) isinstancebytesstr TypeError)Zaddressrrr is_abstract_socket_namespacets    r7cCs&||t}|dk r"d|jd<dS)Ntempdir)rcurrent_process_config)rmtreer8r9rrr _remove_temp_dirsr<cCsftjd}|dkrbddl}ddl}|jdd}td|tdt |j |fdd|tjd<|S)Nr8rzpymp-)prefixzcreated temp directory %si)r exitpriority) rr9r:getshutiltempfileZmkdtemprrr<r;)r8r@rArrr r s  c Csftt}||D]H\\}}}}z ||Wqtk r^}ztd|W5d}~XYqXqdS)Nz after forker raised exception %s)list_afterfork_registryitemssort Exceptionr)rDindexZidentfuncobjerrr _run_after_forkerss  rKcCs|tttt||f<dSr)rCnext_afterfork_counterid)rIrHrrr r sc@sFeZdZdZdddZdeeejfddZ dd Z d d Z d d Z dS)rzA Class which supports object finalization using weakrefs rNcCs|dk r&t|ts&td|t||dk r>t|||_n|dkrNtd||_ ||_ |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)r3intr6formattypeweakrefref_weakref ValueError _callback_args_kwargsrL_finalizer_counter_keyosgetpid_pid_finalizer_registry)selfrIcallbackrkwargsr>rrr __init__s"  zFinalize.__init__cCsz ||j=Wntk r(|dYnbX|j|krD|dd}n$|d|j|j|j|j|j|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)rZKeyErrorr]rVrWrXrT)r_Zwrr^rr\resrrr __call__s$  zFinalize.__call__cCsDz t|j=Wntk r Yn Xd|_|_|_|_|_dS)z3 Cancel finalization of the object N)r^rZrcrTrVrWrXr_rrr cancels zFinalize.cancelcCs |jtkS)zS Return whether this finalizer is still waiting to invoke callback )rZr^rfrrr still_activeszFinalize.still_activec Csz |}Wnttfk r(d}YnX|dkr>d|jjSd|jjt|jd|jf}|jrr|dt|j7}|j r|dt|j 7}|j ddk r|dt|j d7}|dS) Nz<%s object, dead>z<%s object, callback=%s__name__z, args=z , kwargs=rz, exitpriority=>) rTAttributeErrorr6 __class__rigetattrrVrWr5rXrZ)r_rIxrrr __repr__s"   zFinalize.__repr__)rNN) ri __module__ __qualname____doc__rbr^rr[r\rergrhrorrrr rs   c stdkr dSdkrddn fddfddttD}|jdd|D]P}t|}|dk rPtd |z |WqPtk rd dl}|YqPXqPdkrtdS) 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 |ddk SNrrprrr z!_run_finalizers..cs|ddk o|dkSrsrrt) minpriorityrr rvrwcsg|]}|r|qSrr).0key)frr #sz#_run_finalizers..T)reversez calling %sr) r^rBrEr?rrF traceback print_excclear)rxkeysrz finalizerr~r)r{rxr _run_finalizers s$      rcCs tp tdkS)z6 Returns true if the process is shutting down N)_exitingrrrr r 8scCstsda|d|d|d|dk rr|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)rZdaemonnameZ_popenZ terminatejoin)rrractive_childrenr9rurrr r(@s        r(c@s,eZdZddZddZddZddZd S) rcCs|t|tjdSr)_resetr rrfrrr rbqszForkAwareThreadLock.__init__cCs"t|_|jj|_|jj|_dSr) threadingZLock_lockacquirereleaserfrrr rus  zForkAwareThreadLock._resetcCs |jSr)r __enter__rfrrr rzszForkAwareThreadLock.__enter__cGs |jj|Sr)r__exit__)r_rrrr r}szForkAwareThreadLock.__exit__N)rirprqrbrrrrrrr rpsc@seZdZddZddZdS)rcCst|dddS)NcSs |jSr)__dict__r)rIrrr rvrwz)ForkAwareLocal.__init__..)r rfrrr rbszForkAwareLocal.__init__cCs t|dfS)Nr)rQrfrrr __reduce__szForkAwareLocal.__reduce__N)rirprqrbrrrrr rs SC_OPEN_MAXcCsNt|dtg}|tt|dD] }t||d||dq(dS)Nr)rBMAXFDrErangelenr[ closerange)fdsirrr rsc CstjdkrdSztjWnttfk r4YnXz@ttjtj}zt|ddt_Wnt|YnXWnttfk rYnXdS)NF)closefd) r/stdincloseOSErrorrUr[opendevnullO_RDONLY)fdrrr _close_stdins   rc CsTztjWnttfk r&YnXztjWnttfk rNYnXdSr)r/stdoutflushrkrUstderrrrrr _flush_std_streamssrcCsxddl}tttt|}t\}}z6||t |gd|dddddddd||dddWSt|t|XdS)NrTrF) _posixsubprocesstuplesortedmaprOr[piperZ fork_execfsencode)pathrZpassfdsrZ errpipe_readZ errpipe_writerrr spawnv_passfdss2   rcGs|D]}t|qdS)z/Close each file descriptor given as an argumentN)r[r)rrrrr close_fdssrcCsZddlm}tddlm}|jddlm}|j t | | dS)zKCleanup multiprocessing resources when multiprocessing tests completed.r)support) forkserver)resource_trackerN) ZtestrrZ_cleanuprrZ _forkserverZ_stoprZ_resource_trackerrZ gc_collectZ reap_children)rrrrrr _cleanup_testss     r)N)N) s       V , *