From 9b8a2b6bfa0a0586f1c25358519c8d8db1260009 Mon Sep 17 00:00:00 2001 From: Michael Fenn Date: Thu, 10 Oct 2013 14:21:07 -0400 Subject: Reporting: misc improvements to collector threading 1. Use a better convention for calling the threading.Thread constructor 2. Add docstring to ReportingStoreThread.run 3. Give the storage thread variable a better name --- src/lib/Bcfg2/Reporting/Collector.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/lib/Bcfg2') diff --git a/src/lib/Bcfg2/Reporting/Collector.py b/src/lib/Bcfg2/Reporting/Collector.py index f348a60dc..febdfed13 100644 --- a/src/lib/Bcfg2/Reporting/Collector.py +++ b/src/lib/Bcfg2/Reporting/Collector.py @@ -29,15 +29,17 @@ class ReportingError(Exception): class ReportingStoreThread(threading.Thread): """Thread for calling the storage backend""" def __init__(self, interaction, storage, group=None, target=None, - name=None, *args, **kwargs): + name=None, args=(), kwargs=None): """Initialize the thread with a reference to the interaction as well as the storage engine to use""" - threading.Thread.__init__(self, group, target, name, args, kwargs) + threading.Thread.__init__(self, group, target, name, args, + kwargs or dict()) self.interaction = interaction self.storage = storage self.logger = logging.getLogger('bcfg2-report-collector') def run(self): + """Call the database storage procedure (aka import)""" try: start = time.time() self.storage.import_interaction(self.interaction) @@ -129,11 +131,11 @@ class ReportingCollector(object): if not interaction: continue - t = ReportingStoreThread(interaction, self.storage) + store_thread = ReportingStoreThread(interaction, self.storage) while len(threading.enumerate()) > 100: self.logger.info("more than 100 threads running, sleeping") time.sleep(1) - t.start() + store_thread.start() except (SystemExit, KeyboardInterrupt): self.logger.info("Shutting down") self.shutdown() -- cgit v1.2.3-1-g7c22