[{)@s<ddlZddlZddlZddlZddlZddlmZddlmZddddd d d d d ddddddgZ dZ dZ dZ dZ dZdZdZdadaddZddZddZddZdd Zdd d Zd!d ZejZejZd"d#Zd$d ZiZ ejZ!Gd%dde"Z#dd&d'Z$d(d Z%da&eee$ej'ej(d)d*Z)ej*e)Gd+dde"Z+Gd,ddej,Z-yej.d-Z/Wne0k rd.Z/YnXd/dZ1d0d1Z2dS)2N)_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)sFcGs trtjt||ndS)N)_loggerlogr)msgargsr*/usr/lib/python3.4/multiprocessing/util.pyr+scGs trtjt||ndS)N)rrDEBUG)rrrrrr/scGs trtjt||ndS)N)rrINFO)rrrrrr3scGs trtjt||ndS)N)rrr)rrrrrr7sc Csddl}|jzts|jtadt_ttdrctjt tj t qtj j t fiftj j t fifnWd|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||r`|j|ndat 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 Vs     cCstjjjd}|dkrddl}ddl}|jdd}td|td|j d|gdd |tjjd_finalizer_counter_keyosgetpid_pid_finalizer_registry)selfr;callbackrkwargsr.rrr__init__s$   zFinalize.__init__c Csy||j=Wntk r,|dYnX|j|krR|dd}n4|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)rPwrrOrrMZresrrr__call__s   %zFinalize.__call__c CsLyt|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_activec Csy|j}Wnttfk r0d}YnX|dkrAdSdt|jd|j}|jr|dt|j7}n|jr|dt|j7}n|jddk r|dt|jd7}n|dS) Nzz) rFAttributeError TypeErrorgetattrrGrHstrrIrK)rPr;xrrr__repr__s    zFinalize.__repr__) rY __module__ __qualname____doc__rSrOrrLrMrVrWrXr`rrrrrs  c stdkrdSdkr+ddnfddfddttjD}|jddxW|D]O\}}td |y |Wqytk rd dl}|jYqyXqyWdkrtjndS) 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|dddk S)Nrr)prrrsz!_run_finalizers..cs&|dddk o%|ddkS)Nrr)rd) minpriorityrrrescs"g|]}|r|qSrr).0r_)frr s z#_run_finalizers..reverseTz calling %sr) rOr4r6r7rr8 traceback print_excclear)rfr6keyZ finalizerrkr)rhrfr_run_finalizerss   %     rocCstptdkS)z6 Returns true if the process is shutting down N)_exitingrrrrr scCstsda|d|d|d|dk rx:|D]/}|jrC|d|j|jjqCqCWx.|D] }|d|j|jqWn|d|ndS)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_childrenr0rdrrrr%s      r%c@s(eZdZddZddZdS)rcCs|jt|tjdS)N)_resetr r)rPrrrrSAs zForkAwareThreadLock.__init__cCs1tj|_|jj|_|jj|_dS)N) threadingZLock_lockacquirerelease)rPrrrrtEszForkAwareThreadLock._resetN)rYrarbrSrtrrrrr@s  c@s(eZdZddZddZdS)rcCst|dddS)NcSs |jjS)N)__dict__rm)r;rrrreLsz)ForkAwareLocal.__init__..)r )rPrrrrSKszForkAwareLocal.__init__cCst|ffS)N)rA)rPrrr __reduce__MszForkAwareLocal.__reduce__N)rYrarbrSrzrrrrrJs   SC_OPEN_MAXcCst|dtg}|j|dtks<tdx>tt|dD]&}tj||d||dqSWdS)Nrz fd too larger})r4MAXFDr7rCrangelenrL closerange)ZfdsirrrrYs  cCsddl}t|}tj\}}zM|j|tj|gd|ddddddd d ||dddSWdtj|tj|XdS) NrTrFr}r}r}r}r}r})_posixsubprocesssortedrLpipeZ fork_execfsencodeclose)pathrZpassfdsrZ errpipe_readZ errpipe_writerrrspawnv_passfdsds   r)3rL itertoolsrDr$ru subprocessrr__all__ZNOTSETrrrrr"r)rr*rrrrr r r WeakValueDictionaryr5countr?r=r rOrJobjectrror rprsr0r%r&rZlocalrsysconfr~r8rrrrrr s`                 R$  (