From cd094f4e8f6a9442267784b3e9926be6a48f046a Mon Sep 17 00:00:00 2001 From: Changbin Liu Date: Mon, 8 Jul 2013 22:59:45 -0400 Subject: [PATCH] Move FuncThread to utils.wrapper utils.wrapper is where wrappers of various Python standard libraries reside Change-Id: I7b3cde5af16596a6bc3e2e9820f456711bb5e070 --- inception/orchestrator.py | 28 ++-------------------------- inception/utils/wrapper.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 inception/utils/wrapper.py diff --git a/inception/orchestrator.py b/inception/orchestrator.py index 55e8be9..1251f6c 100644 --- a/inception/orchestrator.py +++ b/inception/orchestrator.py @@ -31,7 +31,6 @@ import os import Queue import subprocess import sys -import threading import time import traceback @@ -41,6 +40,7 @@ from oslo.config import cfg from inception import __version__ from inception.utils import cmd +from inception.utils import wrapper orchestrator_opts = [ cfg.StrOpt('prefix', @@ -471,7 +471,7 @@ class Orchestrator(object): threads = [] # create and start all threads for func in funcs: - thread = FuncThread(func, exception_queue) + thread = wrapper.FuncThread(func, exception_queue) threads.append(thread) thread.start() # wait for all threads to finish @@ -541,30 +541,6 @@ class Orchestrator(object): print "Inception cloud '%s' has been cleaned up." % self.prefix -class FuncThread(threading.Thread): - """ - thread of calling a partial function, based on the regular thread - by adding a shared-with-others exception queue - """ - def __init__(self, func, exception_queue): - threading.Thread.__init__(self) - self._func = func - self._exception_queue = exception_queue - - def run(self): - """ - Call the function, and put exception in queue if any - """ - try: - self._func() - except Exception: - func_info = (str(self._func.func) + " " + str(self._func.args) + - " " + str(self._func.keywords)) - info = (self.name, func_info, traceback.format_exc()) - print info - self._exception_queue.put(info) - - def main(): """ program starting point diff --git a/inception/utils/wrapper.py b/inception/utils/wrapper.py new file mode 100644 index 0000000..eaa4a38 --- /dev/null +++ b/inception/utils/wrapper.py @@ -0,0 +1,30 @@ +""" +Simple wrappers of various Python standard library modules +""" + +import threading +import traceback + + +class FuncThread(threading.Thread): + """ + thread of calling a partial function, based on the regular thread + by adding a shared-with-others exception queue + """ + def __init__(self, func, exception_queue): + threading.Thread.__init__(self) + self._func = func + self._exception_queue = exception_queue + + def run(self): + """ + Call the function, and put exception in queue if any + """ + try: + self._func() + except Exception: + func_info = (str(self._func.func) + " " + str(self._func.args) + + " " + str(self._func.keywords)) + info = (self.name, func_info, traceback.format_exc()) + print info + self._exception_queue.put(info)