Francesco Romani has uploaded a new change for review.

Change subject: virt: migration: switch to concurrent.thread()
......................................................................

virt: migration: switch to concurrent.thread()

This patch:
1. replaces good usages of threading.Thread() with
   more modern concurrent.thread()
2. replaces bad usages of threading.Thread() - inheritance
   with composition, leveraging concurrent.thread()

there are no intended changes in behaviour.

Change-Id: I23b98be05103529c827e6e21c0ed82cca58cb346
Signed-off-by: Francesco Romani <[email protected]>
---
M vdsm/virt/migration.py
1 file changed, 28 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/63/61463/1

diff --git a/vdsm/virt/migration.py b/vdsm/virt/migration.py
index c4cb107..6efd9f4 100644
--- a/vdsm/virt/migration.py
+++ b/vdsm/virt/migration.py
@@ -23,6 +23,7 @@
 import time
 import libvirt
 
+from vdsm import concurrent
 from vdsm import hooks
 from vdsm import kaxmlrpclib
 from vdsm import response
@@ -78,7 +79,7 @@
     """
 
 
-class SourceThread(threading.Thread):
+class SourceThread(object):
     """
     A thread that takes care of migration on the source vdsm.
     """
@@ -119,7 +120,7 @@
                 'code': 0,
                 'message': 'Migration in progress'}}
         self._progress = 0
-        threading.Thread.__init__(self)
+        self._thread = concurrent.thread(self._run)
         self._preparingMigrationEvt = True
         self._migrationCanceledEvt = threading.Event()
         self._monitorThread = None
@@ -134,6 +135,12 @@
             self._use_convergence_schedule = True
             self.log.debug('convergence schedule set to: %s',
                            str(self._convergence_schedule))
+
+    def start(self):
+        self._thread.start()
+
+    def is_alive(self):
+        return self._thread.is_alive()
 
     @property
     def hibernating(self):
@@ -327,7 +334,7 @@
                            self._outgoingLimit)
             SourceThread.ongoingMigrations.bound = self._outgoingLimit
 
-    def run(self):
+    def _run(self):
         self._update_outgoing_limit()
         try:
             startTime = time.time()
@@ -523,14 +530,12 @@
         yield downtime
 
 
-class DowntimeThread(threading.Thread):
+class DowntimeThread(object):
 
     # avoid grow too large for large VMs
     _WAIT_STEP_LIMIT = 60  # seconds
 
     def __init__(self, vm, downtime, steps):
-        super(DowntimeThread, self).__init__()
-
         self._vm = vm
         self._downtime = downtime
         self._steps = steps
@@ -546,10 +551,19 @@
         # we need the first value to support set_initial_downtime
         self._initial_downtime = next(self._downtimes)
 
-        self.daemon = True
+        self._thread = concurrent.thread(self._run)
+
+    def start(self):
+        self._thread.start()
+
+    def is_alive(self):
+        return self._thread.is_alive()
+
+    def join(self):
+        return self._thread.join()
 
     @utils.traceback()
-    def run(self):
+    def _run(self):
         self._vm.log.debug('migration downtime thread started (%i steps)',
                            self._steps)
 
@@ -595,7 +609,7 @@
         pass
 
 
-class MonitorThread(threading.Thread):
+class MonitorThread(object):
     _MIGRATION_MONITOR_INTERVAL = config.getint(
         'vars', 'migration_monitor_interval')  # seconds
 
@@ -609,13 +623,17 @@
         self._conv_schedule = conv_schedule
         self._use_conv_schedule = use_conv_schedule
         self.downtime_thread = _FakeThreadInterface()
+        self._thread = concurrent.thread(self._run)
+
+    def start(self):
+        self._thread.start()
 
     @property
     def enabled(self):
         return MonitorThread._MIGRATION_MONITOR_INTERVAL > 0
 
     @utils.traceback()
-    def run(self):
+    def _run(self):
         if self.enabled:
             self._vm.log.debug('starting migration monitor thread')
             try:


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I23b98be05103529c827e6e21c0ed82cca58cb346
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/admin/lists/[email protected]

Reply via email to