[Twisted-Python] Problem combining pb and spawnProcess[3]
Hi, I need this for a project, so this is quite urgent. I got no answer to this until now, so I try again. Maybe somebody could tell me where to ask, if nobody knows a solution, tkanks. ------ I have two seperate processes communicating by Perspective Broker. One, the server, shall start an external program and send the output to the client. See code below. I get the following traceback (part of it): --------------------------------------------- File "/export/home/s/stfl/Twisted/twisted/spread/pb.py", line 472, in expressionReceived raise ProtocolError("Non-list expression received.") twisted.spread.pb.ProtocolError: Non-list expression received. Failure: twisted.spread.pb.PBConnectionLost: I've simplified the code to the following: server (listener.py): ----------------------- #!/usr/bin/env python from twisted.spread import pb from twisted.internet import reactor, app, protocol from twisted.cred import authorizer import os class ABPP(protocol.ProcessProtocol): def __init__(self, receiver): self.receiver = receiver def connectionMade(self): print "connection to client-prg made!" # XXX Here the error is triggered mydef = self.receiver.callRemote("receiveMessage", "connection made!") mydef.addCallback(self.t) def t(self, x): print 't:', x class ABListener(pb.Root): def __init__(self): self.receiver = None def remote_takeMessageReceiver(self, receiver): print 'self.receiver = receiver', receiver self.receiver = receiver def remote_dir(self): pp = ABPP(self.receiver) command = ['/bin/ls'] reactor.spawnProcess(pp, command[0], command, env=os.environ) reactor.run() if __name__ == '__main__': import listener ab_app = app.Application("ABListener") ab_app.listenTCP(8848, pb.BrokerFactory(ABListener())) ab_app.run(save=0) client (client.py) ----------------------- #!/usr/bin/env python from twisted.spread import pb from twisted.internet import reactor class MessageReceiver(pb.Referenceable): def remote_receiveMessage(self, message): print 'server echoed:', message, '<br>' class CComHandler: def __init__(self, mr): self.mr = mr self.remRef = None def gotObject(self, object): self.remRef = object mydef = self.remRef.callRemote("takeMessageReceiver", self.mr) mydef.addCallbacks(self.gaveMr, self.gotErr) def gaveMr(self, reason): print 'gave MessageReceiver' mydef = self.remRef.callRemote("dir") mydef.addCallbacks(self.calledDir, self.gotErr) def calledDir(self, reason): print 'called dir remotely<br>' def gotErr(self, reason): print 'Error: %s<br>' % reason reactor.stop() def doDir(): mr = MessageReceiver() c = CComHandler(mr) pb.getObjectAt("localhost", 8848, 30).addCallback(c.gotObject) reactor.run() if __name__ == "__main__": machine = 'mymachine' packages = [('myPackage', 'myVersion')] doDir()
On Friday, June 13, 2003, at 10:44 AM, Stefan Fleiter wrote:
def remote_dir(self): pp = ABPP(self.receiver) command = ['/bin/ls'] reactor.spawnProcess(pp, command[0], command, env=os.environ) reactor.run()
Remove the 'reactor.run()' here. It should probably raise an exception, since the reactor is not reentrant, but there is no reason that you would need to do this.
On Friday, June 13, 2003, at 04:41 PM, Stefan Fleiter wrote:
Wow, I am lucky, Mr. Twisted himself is answering my beginner-Question!
Technically it's "Sir Dr. Twisted, Esq.", to make sure that we don't get confused with Allen, the "Rt. Hon. Rev. Twisted".
So add.run() automatically starts the reactor?
Yup.
Thanks, a million, I was almost loosing my brains. ;-)
Although I've lost my mind with no apparent ill effects, I'd have to suggest keeping the reactor at least 4 feet from your brains at all time. Twisted has NO WARRANTY, so I can't be liable if your eyeballs were to spontaneously melt...
participants (3)
-
Glyph Lefkowitz
-
Stefan Fleiter
-
Stefan Fleiter