a Z^6@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 SUBWARNING multiprocessingz+[%(levelname)s/%(processName)s] %(message)sFcGstrtjt|g|RdSN)_loggerlogrmsgargsr,/usr/lib64/python3.9/multiprocessing/util.pyr,srcGstrtjt|g|RdSr)rrDEBUGrrrr r0srcGstrtjt|g|RdSr)rrINFOrrrr r4srcGstrtjt|g|RdSr)rrrrrrr r8srcCsddl}|zdtsj|tadt_ttdrFtt t t n$tj t diftj t difW|n |0tS)z0 Returns logger used by multiprocessing rN unregisterr)logging _acquireLockr getLogger LOGGER_NAME propagatehasattratexitr#_exit_functionregister _exithandlersremoveappend _releaseLock)r$rrr r <s    r cCsJddl}t}|t}|}|||||rB||dat S)zB Turn on logging and add a handler which prints to stderr rNT) r$r FormatterDEFAULT_LOGGING_FORMAT StreamHandler setFormatter addHandlersetLevel_log_to_stderrr)levelr$logger formatterhandlerrrr r Ws    r cCs tjdkrdSttdrdSdS)NlinuxTgetandroidapilevelF)sysplatformr)rrrr #_platform_supports_abstract_socketsls   r@cCs@|sdSt|tr|ddkSt|tr4|ddkStddS)NFrz(address type of {address!r} unrecognized) isinstancebytesstr TypeError)addressrrr is_abstract_socket_namespacets    rGcCs&||t}|dur"d|jd<dS)Ntempdir)rcurrent_process_config)rmtreerHrIrrr _remove_temp_dirsrLcCsftjd}|durbddl}ddl}|jdd}td|tdt |j |fdd|tjd<|S)NrHrzpymp-)prefixzcreated temp directory %si)r exitpriority) rrIrJgetshutiltempfilemkdtemprrrLrK)rHrPrQrrr r s  r c Cshtt}||D]J\\}}}}z ||Wqty`}ztd|WYd}~qd}~00qdS)Nz after forker raised exception %s)list_afterfork_registryitemssort Exceptionr)rUindexidentfuncobjerrr _run_after_forkerss  r]cCs|tttt||f<dSr)rTnext_afterfork_counterid)r[rZrrr r sr c@sFeZdZdZdddZdeeejfddZ dd Z d d Z d d Z dS)rzA 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)rBintrEformattypeweakrefref_weakref ValueError _callback_args_kwargsr^_finalizer_counter_keyosgetpid_pid_finalizer_registry)selfr[callbackrkwargsrNrrr __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)rlKeyErrorrorhrirjrf)rqwrrprrnresrrr __call__s    zFinalize.__call__cCsBz t|j=WntyYn 0d|_|_|_|_|_dS)z3 Cancel finalization of the object N)rprlrurfrhrirjrqrrr cancels  zFinalize.cancelcCs |jtvS)zS Return whether this finalizer is still waiting to invoke callback )rlrpryrrr still_activeszFinalize.still_activec Csz |}Wnttfy&d}Yn0|durz<%s object, callback=%s__name__z, args=z , kwargs=rz, exitpriority=>) rfAttributeErrorrE __class__r|getattrrhrirDrjrl)rqr[xrrr __repr__s"   zFinalize.__repr__)rNN) r| __module__ __qualname____doc__rtrprrmrnrxrzr{rrrrr rs   rc 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 |dduSNrrprrr z!_run_finalizers..cs|dduo|dkSrrr) minpriorityrr rrcsg|]}|r|qSrr).0key)frr #rz#_run_finalizers..T)reversez calling %sr) rprSrVrOrrW traceback print_excclear)rkeysr finalizerrr)rrr _run_finalizers s$       rcCs tp tduS)z6 Returns true if the process is shutting down N)_exitingrrrr r 8sr 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)rdaemonname_popen terminatejoin)rrractive_childrenrIrrrr r+@s        r+c@s,eZdZddZddZddZddZd S) rcCs.t|_|jj|_|jj|_t|tjdSr) threadingLock_lockacquirereleaser r_at_fork_reinitryrrr rtqs   zForkAwareThreadLock.__init__cCs|jdSr)rrryrrr rwsz#ForkAwareThreadLock._at_fork_reinitcCs |jSr)r __enter__ryrrr rzszForkAwareThreadLock.__enter__cGs |jj|Sr)r__exit__)rqrrrr r}szForkAwareThreadLock.__exit__N)r|rrrtrrrrrrr rpsrc@seZdZddZddZdS)rcCst|dddS)NcSs |jSr)__dict__r)r[rrr rrz)ForkAwareLocal.__init__..)r ryrrr rtszForkAwareLocal.__init__cCs t|dfS)Nr)rcryrrr __reduce__szForkAwareLocal.__reduce__N)r|rrrtrrrrr rsr SC_OPEN_MAXcCsNt|dtg}|tt|dD] }t||d||dq(dS)Nr)rSMAXFDrVrangelenrm closerange)fdsirrr rsrc CstjdurdSztjWnttfy2Yn0z@ttjtj}zt|ddt_Wnt|Yn0WnttfyYn0dS)NF)closefd) r>stdincloseOSErrorrgrmopendevnullO_RDONLY)fdrrr _close_stdins   rc CsPztjWnttfy$Yn0ztjWnttfyJYn0dSr)r>stdoutflushr~rgstderrrrrr _flush_std_streamssrcCsddl}tttt|}t\}}zP||t|gd|dddddddd||dddddddWt |t |St |t |0dS)NrTrF) _posixsubprocesstuplesortedmaprarmpipe fork_execfsencoder)pathrpassfdsr errpipe_read errpipe_writerrr spawnv_passfdss     rcGs|D]}t|qdS)z/Close each file descriptor given as an argumentN)rmr)rrrrr close_fdssrcCsZddlm}tddlm}|jddlm}|j t | | dS)zKCleanup multiprocessing resources when multiprocessing tests completed.r)support) forkserver)resource_trackerN) testrr_cleanuprr _forkserver_stopr_resource_trackerr gc_collect reap_children)rrrrrr _cleanup_testss     r)N)N)rdr*r subprocessrr__all__NOTSETrr!r"rr'r2rr7rrrrr r r@rGabstract_sockets_supportedrLr WeakValueDictionaryrTcountr_r]r rprkobjectrrr rrrIr+r,rlocalrsysconfrrWrrrrrrrrrr  sn       V , *