def shutdownDaemons(): """ Stops and joins on worker threads. """ # prevents further worker threads from being spawned torTools.NO_SPAWN = True # stops panel daemons control = getController() for panelImpl in control.getDaemonPanels(): panelImpl.stop() for panelImpl in control.getDaemonPanels(): panelImpl.join() # joins on stem threads torTools.getConn().close() # joins on utility daemon threads - this might take a moment since the # internal threadpools being joined might be sleeping hostnames.stop() resourceTrackers = sysTools.RESOURCE_TRACKERS.values() resolver = connections.getResolver("tor") if connections.isResolverAlive("tor") else None for tracker in resourceTrackers: tracker.stop() if resolver: resolver.stop() # sets halt flag (returning immediately) for tracker in resourceTrackers: tracker.join() if resolver: resolver.join() # joins on halted resolver
def shutdownDaemons(): """ Stops and joins on worker threads. """ # prevents further worker threads from being spawned torTools.NO_SPAWN = True # stops panel daemons control = getController() for panelImpl in control.getDaemonPanels(): panelImpl.stop() for panelImpl in control.getDaemonPanels(): panelImpl.join() # joins on TorCtl event thread torTools.getConn().close() # joins on utility daemon threads - this might take a moment since the # internal threadpools being joined might be sleeping hostnames.stop() resourceTrackers = sysTools.RESOURCE_TRACKERS.values() resolver = connections.getResolver("tor") if connections.isResolverAlive( "tor") else None for tracker in resourceTrackers: tracker.stop() if resolver: resolver.stop() # sets halt flag (returning immediately) for tracker in resourceTrackers: tracker.join() if resolver: resolver.join() # joins on halted resolver
def showPrompt(): # For Python 2.6 and earlier cycling history via the readline module with # up/down is buggy with a color prompt. For more information see: # http://bugs.python.org/issue12972 # # To work around this while keeping a color prompt I'm padding the prompt # with extra reset encodings so its length is non-rendered higher (around # sixty characters). There's two ways that this can go wrong... # - if the user uses up/down to display input longer than this non-rendered # length then the original bug will manifest (screwed up prompt) # - if the terminal's width is smaller than the non-rendered prompt length # then the cursor and some movement will be displaced if COLOR_PROMPT: prompt = format(">>> ", Color.GREEN, Attr.BOLD) majorVersion = sys.version_info[0] minorVersion = sys.version_info[1] if majorVersion <= 2 and minorVersion <= 6: prompt += "\x1b[0m" * 10 else: prompt = ">>> " input = "" # sets up tab autocompetion torCommands = TorControlCompleter() readline.parse_and_bind("tab: complete") readline.set_completer(torCommands.complete) # Essentially disables autocompletion by word delimiters. This is because # autocompletion options are full commands (ex. "GETINFO version") so we want # "GETINFO" to match to all the options rather than be treated as a complete # command by itself. readline.set_completer_delims("\n") interpretor = ControlInterpretor() print INIT_MSG while True: try: input = raw_input(prompt) _, outputEntry = interpretor.handleQuery(input) except (KeyboardInterrupt, Exception), exc: if isinstance(exc, InterpretorClosed) and str(exc): print format(str(exc), *ERROR_FORMAT) # moves cursor to the next line and terminates (most commonly # KeyboardInterrupt and EOFErro) print torTools.NO_SPAWN = True torTools.getConn().close() # stop daemons hostnames.stop() break for line in outputEntry: outputLine = "" for msg, msgFormat in line: outputLine += format(msg, *msgFormat) print outputLine