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 NcCsx|dkst|tkst|dk r0tj|||_n |dk s_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)rKKeyErrorrNrGrHrIrF)rPwrrOrrMresrrr__call__s  zFinalize.__call__c CsDy t|j=Wntk r Yn Xd|_|_|_|_|_dS)z3 Cancel finalization of the object N)rOrKrTrFrGrHrI)rPrrrcancels  zFinalize.cancelcCs |jtkS)zS Return whether this finalizer is still waiting to invoke callback )rKrO)rPrrr 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=>) rFAttributeError TypeError __class__rZgetattrrGrHstrrIrK)rPr;xrrr__repr__s    zFinalize.__repr__) rZ __module__ __qualname____doc__rSrOrrLrMrWrXrYrbrrrrrs 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)rf) minpriorityrrrgscsg|]}|r|qSrr).0key)frr sz#_run_finalizers..T)reversez calling %sr) rOr4r7r1rr8 traceback print_excclear)rhkeysrj finalizerrnr)rkrhr_run_finalizerss$       rscCs 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)rtZdaemonnameZ_popenZ terminatejoin)rrrsactive_childrenr0rfrrrr%s       r%c@s,eZdZddZddZddZddZd S) rcCs|jt|tjdS)N)_resetr r)rPrrrrSKszForkAwareThreadLock.__init__cCs"tj|_|jj|_|jj|_dS)N) threadingZLock_lockacquirerelease)rPrrrrxOs  zForkAwareThreadLock._resetcCs |jjS)N)rz __enter__)rPrrrr}TszForkAwareThreadLock.__enter__cGs |jj|S)N)rz__exit__)rPrrrrr~WszForkAwareThreadLock.__exit__N)rZrcrdrSrxr}r~rrrrrJsc@seZdZddZddZdS)rcCst|dddS)NcSs |jjS)N)__dict__rp)r;rrrrg]sz)ForkAwareLocal.__init__..)r )rPrrrrS\szForkAwareLocal.__init__cCs t|ffS)N)rA)rPrrr __reduce__^szForkAwareLocal.__reduce__N)rZrcrdrSrrrrrr[s SC_OPEN_MAXcCsft|dtg}|j|dtks,tdx4tt|dD] }tj||d||dq>WdS)Nrz fd too larger)r4MAXFDr7rCrangelenrL closerange)Zfdsirrrrjs cCstjdkrdSytjjWnttfk r4YnXy@tjtjtj}yt|ddt_Wntj|YnXWnttfk rYnXdS)NF)closefd) sysstdincloseOSError ValueErrorrLopendevnullO_RDONLY)fdrrr _close_stdints   rcCsTytjjWnttfk r&YnXytjjWnttfk rNYnXdS)N)rstdoutflushr\rstderrrrrr_flush_std_streamssrcCstddl}tttt|}tj\}}z2|j|tj|gd|ddddddd d ||dddStj |tj |XdS) NrTrFrrrrrr) _posixsubprocesstuplesortedmaprBrLpipeZ fork_execfsencoder)pathrZpassfdsrZ errpipe_readZ errpipe_writerrrspawnv_passfdss   r)N)N)6rL itertoolsrrDr$ry subprocessrr__all__ZNOTSETrrrrr"r)rr*rrrrr r r WeakValueDictionaryr5countr?r=r rOrJobjectrrsr rtrwr0r%r&rZlocalrsysconfrr8rrrrrrrr sf      S ,(