commit 94edb695c859011f6d462a34eadbecea56771697 Author: Damian Johnson atagar@torproject.org Date: Fri Oct 18 11:55:45 2013 -0700
Moving daemon shutdown into starter
Well, that was silly. We always want to shut down daemons on termination so we had three _shutdown_daemons() calls sprinkled around. Moving this to a single spot at the end of the starter. --- arm/controller.py | 32 ++------------------------------ arm/starter.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 32 deletions(-)
diff --git a/arm/controller.py b/arm/controller.py index 0b6b383..190aee5 100644 --- a/arm/controller.py +++ b/arm/controller.py @@ -23,7 +23,7 @@ import arm.connections.connPanel
from stem.control import State, Controller
-from arm.util import connections, hostnames, panel, sysTools, torConfig, torTools +from arm.util import connections, panel, torConfig, torTools
from stem.util import conf, enum, log, system
@@ -469,34 +469,6 @@ class Controller: try: torTools.getConn().shutdown() except IOError, exc: arm.popups.showMsg(str(exc), 3, curses.A_BOLD)
-def shutdownDaemons(): - """ - Stops and joins on worker threads. - """ - - # prevents further worker threads from being spawned - torTools.NO_SPAWN = True - - # stops panel daemons - control = getController() - - if control: - 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.get_resolver() if connections.get_resolver().is_alive() 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 heartbeatCheck(isUnresponsive): """ Logs if its been ten seconds since the last BW event. @@ -635,5 +607,5 @@ def start_arm(stdscr): isKeystrokeConsumed = panelImpl.handleKey(key) if isKeystrokeConsumed: break
- shutdownDaemons() + panel.HALT_ACTIVITY = True
diff --git a/arm/starter.py b/arm/starter.py index 757cf04..d7c68f9 100644 --- a/arm/starter.py +++ b/arm/starter.py @@ -18,7 +18,10 @@ import time import arm import arm.controller import arm.logPanel +import arm.util.connections +import arm.util.hostnames import arm.util.panel +import arm.util.sysTools import arm.util.torConfig import arm.util.torTools import arm.util.uiTools @@ -261,6 +264,48 @@ def _armrc_dump(armrc_path): return "[unable to read file: %s]" % exc.strerror
+def _shutdown_daemons(): + """ + Stops and joins on worker threads. + """ + + # prevents further worker threads from being spawned + arm.util.torTools.NO_SPAWN = True + + # stops panel daemons + control = arm.controller.getController() + + if control: + for panel_impl in control.getDaemonPanels(): + panel_impl.stop() + + for panel_impl in control.getDaemonPanels(): + panel_impl.join() + + # joins on stem threads + arm.util.torTools.getConn().close() + + # joins on utility daemon threads - this might take a moment since the + # internal threadpools being joined might be sleeping + + arm.util.hostnames.stop() + + resourceTrackers = arm.util.sysTools.RESOURCE_TRACKERS.values() + resolver = arm.util.connections.get_resolver() if arm.util.connections.get_resolver().is_alive() 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 main(): config = stem.util.conf.get_config("arm") config.set('attribute.start_time', str(int(time.time()))) @@ -403,7 +448,6 @@ def main(): curses.wrapper(arm.controller.start_arm) except UnboundLocalError as exc: if os.environ['TERM'] != 'xterm': - arm.controller.shutdownDaemons() print CONFIG['msg.unknown_term'].format(term = os.environ['TERM']) else: raise exc @@ -415,7 +459,8 @@ def main(): # is set) but I've never seen it happen in practice.
arm.util.panel.HALT_ACTIVITY = True - arm.controller.shutdownDaemons() + finally: + _shutdown_daemons()
if __name__ == '__main__': main()
tor-commits@lists.torproject.org