Browse Source

Move FuncThread to utils.wrapper

utils.wrapper is where wrappers of various Python standard libraries
reside

Change-Id: I7b3cde5af16596a6bc3e2e9820f456711bb5e070
Changbin Liu 5 years ago
parent
commit
cd094f4e8f
2 changed files with 32 additions and 26 deletions
  1. 2
    26
      inception/orchestrator.py
  2. 30
    0
      inception/utils/wrapper.py

+ 2
- 26
inception/orchestrator.py View File

@@ -31,7 +31,6 @@ import os
31 31
 import Queue
32 32
 import subprocess
33 33
 import sys
34
-import threading
35 34
 import time
36 35
 import traceback
37 36
 
@@ -41,6 +40,7 @@ from oslo.config import cfg
41 40
 
42 41
 from inception import __version__
43 42
 from inception.utils import cmd
43
+from inception.utils import wrapper
44 44
 
45 45
 orchestrator_opts = [
46 46
     cfg.StrOpt('prefix',
@@ -471,7 +471,7 @@ class Orchestrator(object):
471 471
             threads = []
472 472
             # create and start all threads
473 473
             for func in funcs:
474
-                thread = FuncThread(func, exception_queue)
474
+                thread = wrapper.FuncThread(func, exception_queue)
475 475
                 threads.append(thread)
476 476
                 thread.start()
477 477
             # wait for all threads to finish
@@ -541,30 +541,6 @@ class Orchestrator(object):
541 541
         print "Inception cloud '%s' has been cleaned up." % self.prefix
542 542
 
543 543
 
544
-class FuncThread(threading.Thread):
545
-    """
546
-    thread of calling a partial function, based on the regular thread
547
-    by adding a shared-with-others exception queue
548
-    """
549
-    def __init__(self, func, exception_queue):
550
-        threading.Thread.__init__(self)
551
-        self._func = func
552
-        self._exception_queue = exception_queue
553
-
554
-    def run(self):
555
-        """
556
-        Call the function, and put exception in queue if any
557
-        """
558
-        try:
559
-            self._func()
560
-        except Exception:
561
-            func_info = (str(self._func.func) + " " + str(self._func.args) +
562
-                         " " + str(self._func.keywords))
563
-            info = (self.name, func_info, traceback.format_exc())
564
-            print info
565
-            self._exception_queue.put(info)
566
-
567
-
568 544
 def main():
569 545
     """
570 546
     program starting point

+ 30
- 0
inception/utils/wrapper.py View File

@@ -0,0 +1,30 @@
1
+"""
2
+Simple wrappers of various Python standard library modules
3
+"""
4
+
5
+import threading
6
+import traceback
7
+
8
+
9
+class FuncThread(threading.Thread):
10
+    """
11
+    thread of calling a partial function, based on the regular thread
12
+    by adding a shared-with-others exception queue
13
+    """
14
+    def __init__(self, func, exception_queue):
15
+        threading.Thread.__init__(self)
16
+        self._func = func
17
+        self._exception_queue = exception_queue
18
+
19
+    def run(self):
20
+        """
21
+        Call the function, and put exception in queue if any
22
+        """
23
+        try:
24
+            self._func()
25
+        except Exception:
26
+            func_info = (str(self._func.func) + " " + str(self._func.args) +
27
+                         " " + str(self._func.keywords))
28
+            info = (self.name, func_info, traceback.format_exc())
29
+            print info
30
+            self._exception_queue.put(info)

Loading…
Cancel
Save