mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
inspection: Have it subclass vmmGObject, cleanup its resources
This commit is contained in:
parent
44869d2e6c
commit
be0118e2fe
@ -236,7 +236,7 @@ class vmmEngine(vmmGObject):
|
||||
if not self.config.support_threading:
|
||||
logging.debug("Libvirt doesn't support threading, skipping.")
|
||||
|
||||
self.inspection_thread = None
|
||||
self.inspection = None
|
||||
self._create_inspection_thread()
|
||||
|
||||
# Counter keeping track of how many manager and details windows
|
||||
@ -470,6 +470,10 @@ class vmmEngine(vmmGObject):
|
||||
uihelpers.cleanup()
|
||||
self.err = None
|
||||
|
||||
if self.inspection:
|
||||
self.inspection.cleanup()
|
||||
self.inspection = None
|
||||
|
||||
if self.timer != None:
|
||||
gobject.source_remove(self.timer)
|
||||
|
||||
@ -540,11 +544,10 @@ class vmmEngine(vmmGObject):
|
||||
"or libvirt is not thread safe.")
|
||||
return
|
||||
from virtManager.inspection import vmmInspection
|
||||
self.inspection_thread = vmmInspection()
|
||||
self.inspection_thread.daemon = True
|
||||
self.inspection_thread.start()
|
||||
self.connect("connection-added", self.inspection_thread.conn_added)
|
||||
self.connect("connection-removed", self.inspection_thread.conn_removed)
|
||||
self.inspection = vmmInspection()
|
||||
self.inspection.start()
|
||||
self.connect("connection-added", self.inspection.conn_added)
|
||||
self.connect("connection-removed", self.inspection.conn_removed)
|
||||
return
|
||||
|
||||
def add_connection(self, uri):
|
||||
|
@ -17,24 +17,39 @@
|
||||
# MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
import time
|
||||
from Queue import Queue, Empty
|
||||
from threading import Thread
|
||||
import logging
|
||||
|
||||
import gobject
|
||||
|
||||
from guestfs import GuestFS
|
||||
|
||||
import logging
|
||||
|
||||
class vmmInspection(Thread):
|
||||
_name = "inspection thread"
|
||||
_wait = 15 # seconds
|
||||
from virtManager.baseclass import vmmGObject
|
||||
|
||||
class vmmInspection(vmmGObject):
|
||||
def __init__(self):
|
||||
Thread.__init__(self, name=self._name)
|
||||
vmmGObject.__init__(self)
|
||||
|
||||
self._thread = Thread(name="inspection thread", target=self._run)
|
||||
self._thread.daemon = True
|
||||
self._wait = 15 * 1000 # 15 seconds
|
||||
|
||||
self._q = Queue()
|
||||
self._conns = dict()
|
||||
self._vmseen = dict()
|
||||
|
||||
def cleanup(self):
|
||||
try:
|
||||
vmmGObject.cleanup(self)
|
||||
|
||||
self._thread = None
|
||||
self._q = Queue()
|
||||
self._conns = {}
|
||||
self._vmseen = {}
|
||||
except:
|
||||
pass
|
||||
|
||||
# Called by the main thread whenever a connection is added or
|
||||
# removed. We tell the inspection thread, so it can track
|
||||
# connections.
|
||||
@ -53,14 +68,19 @@ class vmmInspection(Thread):
|
||||
obj = ("vm_added")
|
||||
self._q.put(obj)
|
||||
|
||||
def run(self):
|
||||
def start(self):
|
||||
# Wait a few seconds before we do anything. This prevents
|
||||
# inspection from being a burden for initial virt-manager
|
||||
# interactivity (although it shouldn't affect interactivity at
|
||||
# all).
|
||||
logging.debug("waiting")
|
||||
time.sleep(self._wait)
|
||||
def cb():
|
||||
self._thread.start()
|
||||
return 0
|
||||
|
||||
logging.debug("waiting")
|
||||
self.add_gobject_timeout(gobject.timeout_add(self._wait, cb))
|
||||
|
||||
def _run(self):
|
||||
while True:
|
||||
logging.debug("ready")
|
||||
self._process_queue()
|
||||
@ -225,3 +245,5 @@ class vmmInspection(Thread):
|
||||
logging.debug("icon: %d bytes", len(icon))
|
||||
if apps:
|
||||
logging.debug("# apps: %d", len(apps))
|
||||
|
||||
vmmGObject.type_register(vmmInspection)
|
||||
|
Loading…
Reference in New Issue
Block a user