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)z0 Returns logger used by multiprocessing rN unregister)loggingZ _acquireLockrZ getLogger LOGGER_NAMEZ propagatehasattratexitr _exit_functionregisterZ _exithandlersremoveappendZ _releaseLock)r!rrrr <s     cCsJddl}t}|jt}|j}|j||j||rB|j|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 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@sLeZdZdZfddfddZdeeejfddZ ddZ d d Z d d Z dS) rzA Class which supports object finalization using weakrefs NcCsT|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)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)rHKeyErrorrKrDrErFrC)rMwrrLrrJresrrr__call__s  zFinalize.__call__c CsDy t|j=Wntk r Yn Xd|_|_|_|_|_dS)z3 Cancel finalization of the object N)rLrHrQrCrDrErF)rMrrrcancels  zFinalize.cancelcCs |jtkS)zS Return whether this finalizer is still waiting to invoke callback )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____doc__rPrLrrIrJrTrUrVr_rrrrrs c stdkr dSdkrddn fddfddttD}|jddxX|D]P}tj|}|dk rRtd |y |WqRtk rd dl}|jYqRXqRWdkrtjdS) 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 S)Nrr)prrrsz!_run_finalizers..cs|ddk o|dkS)Nrr)rc) minpriorityrrrdscsg|]}|r|qSrr).0key)frr sz#_run_finalizers..T)reversez calling %sr) rLr4r7r1rr8 traceback print_excclear)rekeysrg finalizerrkr)rhrer_run_finalizerss$       rpcCs tp tdkS)z6 Returns true if the process is shutting down 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)rqZdaemonnameZ_popenZ terminatejoin)rrrpactive_childrenr0rcrrrr%s       r%c@s,eZdZddZddZddZddZd S) rcCs|jt|tjdS)N)_resetr r)rMrrrrPKszForkAwareThreadLock.__init__cCs"tj|_|jj|_|jj|_dS)N) threadingZLock_lockacquirerelease)rMrrrruOs  zForkAwareThreadLock._resetcCs |jjS)N)rw __enter__)rMrrrrzTszForkAwareThreadLock.__enter__cGs |jj|S)N)rw__exit__)rMrrrrr{WszForkAwareThreadLock.__exit__N)rWr`rarPrurzr{rrrrrJsc@seZdZddZddZdS)rcCst|dddS)NcSs |jjS)N)__dict__rm)r;rrrrd]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$rv subprocessrr__all__ZNOTSETrrrrr"r)rr*rrrrr r r WeakValueDictionaryr5countr?r=r rLrGobjectrrpr rqrtr0r%r&rZlocalrsysconfrr8rrrrrrrr sf      S ,(