connection: tick() isn't reentrant, lock it

We can get weird keyerrors sometimes, if the global tick thread is
scheduled off while a synchronous tick call is run (like after we create
a vm).

Eventually we will do away with manual tick() invocations but this will
do for now.
This commit is contained in:
Cole Robinson 2012-01-29 12:07:39 -05:00
parent f1207cef7b
commit 006ba306f7

View File

@ -94,6 +94,7 @@ class vmmConnection(vmmGObject):
self.state = self.STATE_DISCONNECTED self.state = self.STATE_DISCONNECTED
self.connectThread = None self.connectThread = None
self.connectError = None self.connectError = None
self._ticklock = threading.Lock()
self.vmm = None self.vmm = None
self._caps = None self._caps = None
@ -1462,6 +1463,13 @@ class vmmConnection(vmmGObject):
return (new, origlist, current) return (new, origlist, current)
def tick(self, noStatsUpdate=False): def tick(self, noStatsUpdate=False):
try:
self._ticklock.acquire()
self._tick(noStatsUpdate)
finally:
self._ticklock.release()
def _tick(self, noStatsUpdate=False):
""" main update function: polls for new objects, updates stats, ...""" """ main update function: polls for new objects, updates stats, ..."""
if self.state != self.STATE_ACTIVE: if self.state != self.STATE_ACTIVE:
return return