Please include the following information:
vncdotool version: v1.2.0 / git
We're using vncdotool to automate some GUI click-through testing. We added OCR to it running tesseract as some background process, which uses the Twisted reactor to fork and join these processes. Results are passed via Deferreds, which clashes with vncdotool's use of its Deferres, which must always return self.
- On
VNCDoToolFactory.clientConnectionMade the deferred is called with the instance of the protocol:
class VNCDoToolFactory(rfb.RFBFactory):
protocol = VNCDoToolClient # class
def clientConnectionMade(self, protocol: VNCDoToolClient) -> None:
self.deferred.callback(protocol) # instance
- Both vncdotool.command.build_command_list and vncdotool.api.ThreadedVNCClientProxy.getattr use code to get the unbound methods from the class
VNCDoToolClient — not the bound method from the instance — which then require the 1st parameter self to be that reference to the instance.
class ThreadedVNCClientProxy:
def __getattr__(self, attr: str) -> Any:
method = getattr(self.factory.protocol, attr) # from class
…
def build_command_list(…):
client = VNCDoCLIClient # class
…
factory.deferred.addCallback(client.keyPress, key) # from class
While this late binding of the instance allows command to build up the list of methods before the connection is even established, it is annoying in other cases where other information should be passed via the deferred and easily leads to errors, when a method does not return self at the end: then you get the dreaded None type has not attribute XXX error.
- This needs to be documented somewhere.
- maybe the internal implementation can be changed to use the bound methods.
PS: You also have to be very careful if your implementation raises any exception, which is translated to a Failure instance by Twisted and the deferred switches to errback mode, where only errbacks are executed until one returns a non-Failure instance. If you do not handle that case all following calls of vncdotool.api will be ignored until you reset the deferred to normal callback mode. Basically any raised Exception is fatal for vncdotool.api.
Please include the following information:
vncdotool version: v1.2.0 / git
We're using
vncdotoolto automate some GUI click-through testing. We added OCR to it runningtesseractas some background process, which uses the Twisted reactor toforkandjointhese processes. Results are passed viaDeferreds, which clashes withvncdotool's use of itsDeferres, which must always returnself.VNCDoToolFactory.clientConnectionMadethe deferred is called with the instance of the protocol:VNCDoToolClient— not the bound method from the instance — which then require the 1st parameterselfto be that reference to the instance.While this late binding of the instance allows
commandto build up the list of methods before the connection is even established, it is annoying in other cases where other information should be passed via thedeferredand easily leads to errors, when a method does notreturn selfat the end: then you get the dreadedNone type has not attribute XXXerror.PS: You also have to be very careful if your implementation raises any exception, which is translated to a
Failureinstance by Twisted and thedeferredswitches toerrbackmode, where onlyerrbacks are executed until one returns a non-Failureinstance. If you do not handle that case all following calls ofvncdotool.apiwill be ignored until you reset thedeferredto normal callback mode. Basically any raised Exception is fatal forvncdotool.api.