ia64/xen-unstable

changeset 12587:dc1c8ae0a87a

Do not bother waiting for the old HttpServer and UnixHttpServer threads when
shutting down -- they don't have exit handling themselves and ought to just
be made daemon threads.

Added some logging to dialog shutdown problems.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Mon Nov 27 12:50:30 2006 +0000 (2006-11-27)
parents b6c6a1efbfaf
children 57422757b04c
files tools/python/xen/xend/server/SrvServer.py
line diff
     1.1 --- a/tools/python/xen/xend/server/SrvServer.py	Mon Nov 27 12:00:01 2006 +0000
     1.2 +++ b/tools/python/xen/xend/server/SrvServer.py	Mon Nov 27 12:50:30 2006 +0000
     1.3 @@ -62,12 +62,14 @@ class XendServers:
     1.4  
     1.5      def __init__(self):
     1.6          self.servers = []
     1.7 +        self.cleaningUp = False
     1.8  
     1.9      def add(self, server):
    1.10          self.servers.append(server)
    1.11  
    1.12      def cleanup(self, signum = 0, frame = None):
    1.13          log.debug("SrvServer.cleanup()")
    1.14 +        self.cleaningUp = True
    1.15          for server in self.servers:
    1.16              try:
    1.17                  server.shutdown()
    1.18 @@ -84,7 +86,9 @@ class XendServers:
    1.19          Vifctl.network('start')
    1.20          threads = []
    1.21          for server in self.servers:
    1.22 -            thread = Thread(target=server.run)
    1.23 +            thread = Thread(target=server.run, name=server.__class__.__name__)
    1.24 +            if isinstance(server, HttpServer):
    1.25 +                thread.setDaemon(True)
    1.26              thread.start()
    1.27              threads.append(thread)
    1.28  
    1.29 @@ -117,12 +121,16 @@ class XendServers:
    1.30          #   Reason:   The above will cause python signal handlers to be
    1.31          #             blocked so we're not able to catch SIGTERM in any
    1.32          #             way for cleanup
    1.33 -        runningThreads = len([t for t in threads if t.isAlive()])
    1.34 -        while runningThreads > 0:
    1.35 +        runningThreads = threads
    1.36 +        while len(runningThreads) > 0:
    1.37              try:
    1.38                  for t in threads:
    1.39                      t.join(1.0)
    1.40 -                runningThreads = len([t for t in threads if t.isAlive()])
    1.41 +                runningThreads = [t for t in threads
    1.42 +                                  if t.isAlive() and not t.isDaemon()]
    1.43 +                if self.cleaningUp and len(runningThreads) > 0:
    1.44 +                    log.debug("Waiting for %s." %
    1.45 +                              [x.getName() for x in runningThreads])
    1.46              except:
    1.47                  pass
    1.48