Skip to content
Browse files

client: avoid nested calls to _expectCompare

Too many updates causes recursion errors
  • Loading branch information...
1 parent 7f88af2 commit f73d5e29a31b0c41ab773e6a49bb31ec477170c4 Marc Sibson committed Jan 28, 2011
Showing with 21 additions and 17 deletions.
  1. +21 −17 vncdotool/client.py
View
38 vncdotool/client.py
@@ -8,7 +8,7 @@
import rfb
from twisted.internet import reactor, defer
-from twisted.internet.defer import Deferred
+from twisted.internet.defer import Deferred, DeferredQueue
import math
import operator
@@ -132,10 +132,10 @@ def captureScreen(self, filename):
# request initial screen update
self.framebufferUpdateRequest()
- self.deferred = defer.Deferred()
- self.deferred.addCallback(self._captureSave, filename)
+ d = self.updates.get()
+ d.addCallback(self._captureSave, filename)
- return self.deferred
+ return d
def _captureSave(self, data, filename):
self.screen.save(filename)
@@ -155,26 +155,29 @@ def expectScreen(self, filename, maxrms=0):
from PIL import Image
self.expected = Image.open(filename).histogram()
- self.deferred = defer.Deferred()
- self.deferred.addCallback(self._expectCompare, maxrms)
+ self.deferred = Deferred()
+ d = self.updates.get()
+ d.addCallback(self._expectCompare, maxrms)
return self.deferred
- def _expectCompare(self, data, maxrms):
- hist = self.screen.histogram()
+ def _expectCompare(self, image, maxrms):
+ hist = image.histogram()
rms = math.sqrt(
reduce(operator.add,
map(lambda a,b: (a-b)**2, hist, self.expected)) / len(hist))
self.log('rms %d', rms)
- if rms > maxrms:
- self.deferred = defer.Deferred()
- self.deferred.addCallback(self._expectCompare, maxrms)
- return self.deferred
+ if rms < maxrms:
+ self.deferred.callback(self)
+ self.deferred = None
+ return
+
+ d = self.updates.get()
+ d.addCallback(self._expectCompare, maxrms)
- return self
def mouseMove(self, x, y):
""" Move the mouse pointer to position (x, y)
@@ -194,6 +197,10 @@ def vncConnectionMade(self):
self.setPixelFormat()
self.factory.deferred.callback(self)
+ def framebufferUpdateRequest(self):
+ self.updates = DeferredQueue()
+ rfb.RFBClient.framebufferUpdateRequest(self)
+
def bell(self):
print 'ding'
@@ -221,10 +228,7 @@ def updateRectangle(self, x, y, width, height, data):
else:
self.screen.paste(update, (x, y))
- if self.deferred:
- d = self.deferred
- self.deferred = None
- d.callback(data)
+ self.updates.put(self.screen)
class VNCDoToolFactory(rfb.RFBFactory):

0 comments on commit f73d5e2

Please sign in to comment.
Something went wrong with that request. Please try again.