baseclass: Add helper for launching daemon thread

And use it in a few spots
This commit is contained in:
Cole Robinson 2014-09-12 11:28:27 -04:00
parent 5041529822
commit df32f9331d
3 changed files with 12 additions and 12 deletions

View File

@ -21,6 +21,7 @@
import logging
import os
import sys
import threading
import traceback
from virtManager import config
@ -119,6 +120,13 @@ class vmmGObject(GObject.GObject):
# Function generates 2 temporary refs, so adjust total accordingly
return (sys.getrefcount(self) - 2)
def _start_thread(self, target=None, name=None, args=None, kwargs=None):
# Helper for starting a daemonized thread
t = threading.Thread(target=target, name=name,
args=args or [], kwargs=kwargs or {})
t.daemon = True
t.start()
def connect_once(self, signal, func, *args):
id_list = []

View File

@ -24,7 +24,6 @@ import logging
import os
import re
import socket
import threading
import time
import traceback
@ -86,7 +85,6 @@ class vmmConnection(vmmGObject):
self._uri = "xen:///"
self._state = self._STATE_DISCONNECTED
self._connectThread = None
self._connectError = None
self._backend = virtinst.VirtualConnection(self._uri)
self._closing = False
@ -842,7 +840,7 @@ class vmmConnection(vmmGObject):
self.emit("mediadev-added", mediadev)
self.idle_add(_add_idle)
threading.Thread(target=_add_thread, name="AddMediadev").start()
self._start_thread(_add_thread, "nodedev=%s AddMediadev" % name)
def _nodedev_mediadev_removed(self, ignore1, name):
if name not in self._mediadevs:
@ -934,10 +932,8 @@ class vmmConnection(vmmGObject):
else:
logging.debug("Scheduling background open thread for " +
self.get_uri())
self._connectThread = threading.Thread(target=self._open_thread,
name="Connect %s" % self.get_uri())
self._connectThread.setDaemon(True)
self._connectThread.start()
self._start_thread(self._open_thread,
"Connect %s" % self.get_uri())
def _do_creds_password(self, creds):
try:
@ -1066,7 +1062,6 @@ class vmmConnection(vmmGObject):
return pollhelpers.fetch_vms(self._backend, self._vms.copy(),
(lambda obj, key: vmmDomain(self, obj, key)))
def _obj_signal_proxy(self, obj, signal, key):
ignore = obj
self.emit(signal, key)

View File

@ -267,10 +267,7 @@ class vmmEngine(vmmGObject):
self.idle_add(connect, uri)
add_next_to_queue()
thread = threading.Thread(name="Autostart thread",
target=handle_queue, args=())
thread.daemon = True
thread.start()
self._start_thread(handle_queue, "Conn autostart thread")
def _do_vm_removed(self, conn, connkey):