3 \n.@sddlZddlZddlZddlZddlZddlZddlmZddlm Z ddddd d d d d ddddddgZ dZ dZ dZ dZdZdZdZdadaddZddZddZddZdd Zd6d d Zd!d ZejZejZd"d#Zd$d Z iZ!ejZ"Gd%dde#Z$d7d&d'Z%d(d Z&da'eee%e j(e j)fd)d*Z*ej+e*Gd+dde#Z,Gd,ddej-Z.yej/d-Z0Wne1k rd.Z0YnXd/dZ2d0d1Z3d2d3Z4d4d5Z5dS)8N)_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 Zmultiprocessingz+[%(levelname)s/%(processName)s] %(message)sFcGstrtjt|f|dS)N)_loggerlogr)msgargsr,/usr/lib64/python3.6/multiprocessing/util.pyr,scGstrtjt|f|dS)N)rrDEBUG)rrrrrr0scGstrtjt|f|dS)N)rrINFO)rrrrrr4scGstrtjt|f|dS)N)rrr)rrrrrr8sc Cs|ddl}|jz\tsj|jtadt_ttdrFtjt tj t n$tj j t fiftj j t fifWd|jXtS)Nr unregister)loggingZ _acquireLockrZ getLogger LOGGER_NAMEZ propagatehasattratexitr _exit_functionregisterZ _exithandlersremoveappendZ _releaseLock)r!rrrr <s     cCsJddl}t}|jt}|j}|j||j||rB|j|dat S)NrT) r!r Z FormatterDEFAULT_LOGGING_FORMATZ StreamHandlerZ setFormatterZ addHandlerZsetLevel_log_to_stderrr)levelr!ZloggerZ formatterZhandlerrrrr Ws    cCsdtjjjd}|dkr`ddl}ddl}|jdd}td|td|j |gdd|tjjd<|S) Ntempdirrzpymp-)prefixzcreated temp directory %sd)r exitpriorityi) rcurrent_processZ_configgetshutiltempfileZmkdtemprrZrmtree)r,r2r3rrrr ms  cCsjttj}|jxP|D]H\\}}}}y ||Wqtk r`}ztd|WYdd}~XqXqWdS)Nz after forker raised exception %s)list_afterfork_registryitemssort Exceptionr)r6indexZidentfuncobjerrr_run_after_forkerss  r=cCs|tttt||f<dS)N)r5next_afterfork_counterid)r;r:rrrr sc@sHeZdZfddfddZdeeejfddZddZ dd Z d d Z dS) rNcCsT|dk rtj|||_n||_||_|p*i|_|ttf|_t j |_ |t |j<dS)N) weakrefref_weakref _callback_args_kwargsr>_finalizer_counter_keyosgetpid_pid_finalizer_registry)selfr;callbackrkwargsr/rrr__init__s  zFinalize.__init__c Csy ||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)rHKeyErrorrKrDrErFrC)rMwrrLrrJresrrr__call__s  zFinalize.__call__c CsDy t|j=Wntk r Yn Xd|_|_|_|_|_dS)N)rLrHrQrCrDrErF)rMrrrcancels  zFinalize.cancelcCs |jtkS)N)rHrL)rMrrr still_activeszFinalize.still_activecCsy |j}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, exitprority=>) rCAttributeError TypeError __class__rWgetattrrDrEstrrFrH)rMr;xrrr__repr__s    zFinalize.__repr__) rW __module__ __qualname__rPrLrrIrJrTrUrVr_rrrrrs c stdkr dSdkrddn fddfddttD}|jddxX|D]P}tj|}|dk rRtd|y |WqRtk rd dl}|jYqRXqRWdkrtjdS) NcSs |ddk S)Nrr)prrrsz!_run_finalizers..cs|ddk o|dkS)Nrr)rb) minpriorityrrrcscsg|]}|r|qSrr).0key)frr sz#_run_finalizers..T)reversez calling %sr) rLr4r7r1rr8 traceback print_excclear)rdkeysrf finalizerrjr)rgrdr_run_finalizerss$       rocCs tp tdkS)N)_exitingrrrrr scCstsda|d|d|d|dk rzx*|D] }|jr2|d|j|jjq2Wx"|D]}|d|j|jq^W|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)rpZdaemonnameZ_popenZ terminatejoin)rrroactive_childrenr0rbrrrr%s       r%c@s,eZdZddZddZddZddZd S) rcCs|jt|tjdS)N)_resetr r)rMrrrrPKszForkAwareThreadLock.__init__cCs"tj|_|jj|_|jj|_dS)N) threadingZLock_lockacquirerelease)rMrrrrtOs  zForkAwareThreadLock._resetcCs |jjS)N)rv __enter__)rMrrrryTszForkAwareThreadLock.__enter__cGs |jj|S)N)rv__exit__)rMrrrrrzWszForkAwareThreadLock.__exit__N)rWr`rarPrtryrzrrrrrJsc@seZdZddZddZdS)rcCst|dddS)NcSs |jjS)N)__dict__rl)r;rrrrc]sz)ForkAwareLocal.__init__..)r )rMrrrrP\szForkAwareLocal.__init__cCs t|ffS)N)type)rMrrr __reduce__^szForkAwareLocal.__reduce__N)rWr`rarPr}rrrrr[s SC_OPEN_MAXcCsRt|dtg}|jx4tt|dD] }tj||d||dq*WdS)Nr)r4MAXFDr7rangelenrI closerange)ZfdsirrrrjscCstjdkrdSytjjWnttfk r4YnXy@tjtjtj}yt|ddt_Wntj|YnXWnttfk rYnXdS)NF)closefd) sysstdincloseOSError ValueErrorrIopendevnullO_RDONLY)fdrrr _close_stdints   rcCsTytjjWnttfk r&YnXytjjWnttfk rNYnXdS)N)rstdoutflushrYrstderrrrrr_flush_std_streamssrcCstddl}tttt|}tj\}}z2|j|tj|gd|ddddddd d ||dddStj |tj |XdS) NrTrFrrrrrr) _posixsubprocesstuplesortedmapintrIpipeZ fork_execfsencoder)pathrZpassfdsrZ errpipe_readZ errpipe_writerrrspawnv_passfdss   r)N)N)6rI itertoolsrrAr$ru subprocessrr__all__ZNOTSETrrrrr"r)rr*rrrrr r r WeakValueDictionaryr5countr?r=r rLrGobjectrror rprsr0r%r&rZlocalrsysconfrr8rrrrrrrr sf      S ,(