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)Nr unregisterr)loggingZ _acquireLockZ _releaseLockrZ getLogger LOGGER_NAMEZ propagatehasattratexitr#_exit_functionregisterZ _exithandlersremoveappend)r$rrr r <s     cCsJddl}t}|t}|}|||||rB||dat S)NrT) 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@sBeZdZd ddZdeeejfddZddZ d d Z d d Z dS)rrNcCs|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)Nzfinalizer no longer registeredz+finalizer ignored because different processz/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|_|_|_|_|_dSr)r^rZrcrTrVrWrXr_rrr cancels zFinalize.cancelcCs |jtkSr)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__rbr^rr[r\rergrhrorrrr rs   c stdkr dSdkrddn fddfddttD}|jdd|D]P}t|}|dk rPtd|z |WqPtk rd dl}|YqPXqPdkrtdS) NcSs |ddk SNrrprrr z!_run_finalizers..cs|ddk o|dkSrrrrs) minpriorityrr rurvcsg|]}|r|qSrr).0key)frr #sz#_run_finalizers..T)reversez calling %sr) r^rBrEr?rrF traceback print_excclear)rwkeysry finalizerr}r)rzrwr _run_finalizers s$      rcCs tp tdkSr)_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_childrenr9rtrrr 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 rurvz)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|qdSr)r[r)rrrrr close_fdssrcCsZddlm}tddlm}|jddlm}|j t | | dS)Nr)support) forkserver)resource_tracker) ZtestrrZ_cleanuprrZ _forkserverZ_stoprZ_resource_trackerrZ gc_collectZ reap_children)rrrrrr _cleanup_testss     r)N)N) s       V , *