Change in vdsm[master]: concurrent: Use new concurrent.thread() utility

nsoffer at redhat.com nsoffer at redhat.com
Mon Aug 17 00:58:29 UTC 2015


Nir Soffer has uploaded a new change for review.

Change subject: concurrent: Use new concurrent.thread() utility
......................................................................

concurrent: Use new concurrent.thread() utility

This patch remove eliminate some boilerplate code by using the new
concurrent.thread() utility for creating threads.

Nice side effect of this refactoring is adding the missing
@utils.traceback() preventing silent failures of this thread.

Change-Id: Id98bcdf7bb6c67583d9d994781e642441c9b8bdd
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M lib/vdsm/libvirtconnection.py
M lib/vdsm/schedule.py
M lib/vdsm/xmlrpc.py
M vdsm/clientIF.py
M vdsm/rpc/bindingxmlrpc.py
5 files changed, 16 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/95/44895/1

diff --git a/lib/vdsm/libvirtconnection.py b/lib/vdsm/libvirtconnection.py
index f7a3926..15ccf33 100644
--- a/lib/vdsm/libvirtconnection.py
+++ b/lib/vdsm/libvirtconnection.py
@@ -27,6 +27,7 @@
 import signal
 
 import libvirt
+from . import concurrent
 from . import utils
 from .password import ProtectedPassword
 from .tool.configurators import passwd
@@ -41,9 +42,8 @@
 
     def start(self):
         assert not self.run
-        self.__thread = threading.Thread(target=self.__run,
-                                         name="libvirtEventLoop")
-        self.__thread.setDaemon(True)
+        self.__thread = concurrent.thread(self.__run, name="libvirtEventLoop",
+                                          logger=log.name)
         self.run = True
         self.__thread.start()
 
@@ -54,7 +54,6 @@
                 self.__thread.join()
             self.__thread = None
 
-    @utils.traceback(on=log.name)
     def __run(self):
         try:
             libvirt.virEventRegisterDefaultImpl()
diff --git a/lib/vdsm/schedule.py b/lib/vdsm/schedule.py
index 05386c7..8407704 100644
--- a/lib/vdsm/schedule.py
+++ b/lib/vdsm/schedule.py
@@ -63,6 +63,7 @@
 import threading
 import time
 
+from . import concurrent
 from . import utils
 
 
@@ -91,8 +92,8 @@
         self._cond = threading.Condition(threading.Lock())
         self._running = False
         self._calls = []
-        self._thread = threading.Thread(target=self._run, name=self._name)
-        self._thread.daemon = True
+        self._thread = concurrent.thread(self._run, name=self._name,
+                                         logger=self._log.name)
 
     def start(self):
         self._log.debug("Starting scheduler %s", self._name)
@@ -137,7 +138,6 @@
                 self._cond.notify()
         return call
 
-    @utils.traceback(on=_log.name)
     def _run(self):
         self._log.debug("started")
         try:
diff --git a/lib/vdsm/xmlrpc.py b/lib/vdsm/xmlrpc.py
index 66d9415..4327790 100644
--- a/lib/vdsm/xmlrpc.py
+++ b/lib/vdsm/xmlrpc.py
@@ -26,6 +26,7 @@
 import sys
 import threading
 
+from . import concurrent
 from .config import config
 from .executor import TaskQueue
 from .utils import traceback
@@ -71,15 +72,14 @@
         if sock is self._STOP:
             return
         self.log.info("Starting request handler for %s:%d", addr[0], addr[1])
-        t = threading.Thread(target=self._process_requests, args=(sock, addr))
-        t.daemon = True
+        t = concurrent.thread(self._process_requests, args=(sock, addr),
+                              logger=self.log.name)
         t.start()
 
     def server_close(self):
         self.queue.clear()
         self.queue.put((self._STOP, self._STOP))
 
-    @traceback(on=log.name)
     def _process_requests(self, sock, addr):
         self.log.info("Request handler for %s:%d started", addr[0], addr[1])
         try:
diff --git a/vdsm/clientIF.py b/vdsm/clientIF.py
index 7b9c490..3834bcb 100644
--- a/vdsm/clientIF.py
+++ b/vdsm/clientIF.py
@@ -39,6 +39,7 @@
 import libvirt
 from vdsm import sslutils
 from vdsm import libvirtconnection
+from vdsm import concurrent
 from vdsm import constants
 from vdsm import utils
 import caps
@@ -108,8 +109,7 @@
             self._netConfigDirty = False
             self._prepareMOM()
             secret.clear()
-            threading.Thread(target=self._recoverThread,
-                             name='clientIFinit').start()
+            concurrent.thread(self._recoverThread, name='clientIFinit').start()
             self.channelListener.settimeout(
                 config.getint('vars', 'guest_agent_timeout'))
             self.channelListener.start()
@@ -290,9 +290,8 @@
     def start(self):
         for binding in self.bindings.values():
             binding.start()
-        self.thread = threading.Thread(target=self._reactor.process_requests,
-                                       name='Reactor thread')
-        self.thread.setDaemon(True)
+        self.thread = concurrent.thread(self._reactor.process_requests,
+                                        name='Reactor thread')
         self.thread.start()
 
     def _getUUIDSpecPath(self, uuid):
@@ -447,7 +446,6 @@
         else:
             raise JsonRpcBindingsError()
 
-    @utils.traceback()
     def _recoverThread(self):
         # Trying to run recover process until it works. During that time vdsm
         # stays in recovery mode (_recover=True), means all api requests
diff --git a/vdsm/rpc/bindingxmlrpc.py b/vdsm/rpc/bindingxmlrpc.py
index 04cdf32..a85b7c4 100644
--- a/vdsm/rpc/bindingxmlrpc.py
+++ b/vdsm/rpc/bindingxmlrpc.py
@@ -30,6 +30,7 @@
 from vdsm.password import (ProtectedPassword,
                            protect_passwords,
                            unprotect_passwords)
+from vdsm import concurrent
 from vdsm import utils
 from vdsm import xmlrpc
 from vdsm.define import doneCode, errCode
@@ -57,7 +58,6 @@
         """
         Register xml-rpc functions and serve clients until stopped
         """
-        @utils.traceback(on=self.log.name)
         def threaded_start():
             self.log.info("XMLRPC server running")
             self._registerFunctions()
@@ -73,9 +73,8 @@
                                        exc_info=True)
             self.log.info("XMLRPC server stopped")
 
-        self._thread = threading.Thread(target=threaded_start,
-                                        name='BindingXMLRPC')
-        self._thread.daemon = True
+        self._thread = concurrent.thread(threaded_start, name='BindingXMLRPC',
+                                         logger=self.log.name)
         self._thread.start()
 
     def add_socket(self, connected_socket, socket_address):


-- 
To view, visit https://gerrit.ovirt.org/44895
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id98bcdf7bb6c67583d9d994781e642441c9b8bdd
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list