ϪfdZddlmZddlmZddlmZddlmZm Z m Z m Z ddl m Z mZmZddlmZddlmZdd lmZmZmZmZmZmZmZd d lmZmZd d lm Z m!Z!m"Z"m#Z#ed GddZ$y)z Twisted application runner. )kill)SIGTERM)stderr)AnyCallableMappingTextIO)Factoryattribattrs) NamedConstant) IReactorCore)FileLogObserverFilteringLogObserverLoggerLogLevelLogLevelFilterPredicateglobalLogBeginnertextFileLogObserver) ExitStatusexit)AlreadyRunningErrorInvalidPIDFileErrorIPIDFile nonePIDFileT)frozencpeZdZdZeZeeZee e Z ee dZ eeej ZeeeZeeegefeZeeddZeeeefeeZeeddZ eeeefeeZ!dd Z"dd Z#dd Z$dd Z%dd Z&ddZ'y)Runnera Twisted application runner. @cvar _log: The logger attached to this class. @ivar _reactor: The reactor to start and run the application in. @ivar _pidFile: The file to store the running process ID in. @ivar _kill: Whether this runner should kill an existing running instance of the application. @ivar _defaultLogLevel: The default log level to start the logging system with. @ivar _logFile: A file stream to write logging output to. @ivar _fileLogObserverFactory: A factory for the file log observer to use when starting the logging system. @ivar _whenRunning: Hook to call after the reactor is running; this is where the application code that relies on the reactor gets called. @ivar _whenRunningArguments: Keyword arguments to pass to C{whenRunning} when it is called. @ivar _reactorExited: Hook to call after the reactor exits. @ivar _reactorExitedArguments: Keyword arguments to pass to C{reactorExited} when it is called. )type)r defaultF).Nc yN_s D/usr/lib/python3/dist-packages/twisted/application/runner/_runner.pyzRunner.Cc yr#r$r%s r'r(zRunner.Er)r*Nc|j}|j |5|j|j|j dddy#1swYyxYw#t $rt tjdYywxYw)z# Run this command. NzAlready running.) _pidFilekillIfRequested startLogging startReactor reactorExitedrrr EX_CONFIG)selfpidFiles r'runz Runner.runHs~--   %!!#!!#""$ % % % #  %%'9 :  s.A&1AA&A#A&#A&&#B  B c|j}|jr|turttj dy |j }|j|jjd|t|tttj yy#t$rttjdYyt$rttjdYywxYw)zj If C{self._kill} is true, attempt to kill a running instance of the application. zNo PID file specified.NzUnable to read PID file.zInvalid PID file.zTerminating process: {pid})pid)r-_killrrrEX_USAGEreadOSErrorEX_IOERRr EX_DATAERRr/_loginforrEX_OK)r3r4r7s r'r.zRunner.killIfRequested[s -- ::+%Z((*BC lln     IINN7SN A g  !! " 1  Z((*DE& Z**,?@ sB%%#C/ "C/.C/c|j}|j}||}t|j}t ||g}t j |gy)z= Start the L{twisted.logger} logging system. )defaultLogLevelN)_logFile_fileLogObserverFactoryr_defaultLogLevelrrbeginLoggingTo)r3logFilefileLogObserverFactoryfileLogObserverlogLevelPredicatefilteringObservers r'r/zRunner.startLogging|s\--!%!=!=093 11 1CTBUV((*;)<=r*c|jj|j|jj d|jj y)z Register C{self._whenRunning} with the reactor so that it is called once the reactor is running, then start the reactor. zStarting reactor...N)_reactorcallWhenRunning whenRunningr>r?r5r3s r'r0zRunner.startReactors= %%d&6&67 ,- r*c<|jdi|jy)z Call C{self._whenRunning} with C{self._whenRunningArguments}. @note: This method is called after the reactor starts running. Nr$) _whenRunning_whenRunningArgumentsrPs r'rOzRunner.whenRunnings 7D667r*c<|jdi|jy)z Call C{self._reactorExited} with C{self._reactorExitedArguments}. @note: This method is called after the reactor exits. Nr$)_reactorExited_reactorExitedArgumentsrPs r'r1zRunner.reactorExiteds ;d::;r*)returnN)(__name__ __module__ __qualname____doc__rr>r rrMrrr-boolr8r rr?rEr rrCrrrrDrRrstrrr dictrSrUrVr5r.r/r0rOr1r$r*r'rrs0 8D<(H8[9H e ,E=(--H662H$ vh/ 0:Mx 2NON$'#s(*;WT]S&B>$8risb 11''$4$UUdF<F<F