From 8a8a47998438707f988838b505b98b99a11ce687 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Wed, 19 Feb 2014 08:08:37 -0500 Subject: core: only shut down core once --- src/lib/Bcfg2/Server/Core.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py index 38daa870e..03bc7bff4 100644 --- a/src/lib/Bcfg2/Server/Core.py +++ b/src/lib/Bcfg2/Server/Core.py @@ -189,6 +189,12 @@ class BaseCore(object): self.setup = setup atexit.register(self.shutdown) + #: if :func:`Bcfg2.Server.Core.shutdown` is called explicitly, + #: then :mod:`atexit` calls it *again*, so it gets called + #: twice. This is potentially bad, so we use + #: :attr:`Bcfg2.Server.Core._running` as a flag to determine + #: if the core needs to be shutdown, and only do it once. + self._running = True #: Threading event to signal worker threads (e.g., #: :attr:`fam_thread`) to shutdown @@ -451,9 +457,13 @@ class BaseCore(object): def shutdown(self): """ Perform plugin and FAM shutdown tasks. """ + if not self._running: + self.logger.debug("%s: Core already shut down" % self.name) + return self.logger.info("%s: Shutting down core..." % self.name) if not self.terminate.isSet(): self.terminate.set() + self._running = False self.fam.shutdown() self.logger.info("%s: FAM shut down" % self.name) for plugin in list(self.plugins.values()): -- cgit v1.2.3-1-g7c22