[Twisted-Python] Problem combining pb and spawnProcess[2]

Stefan Fleiter sf.lists at web.de
Wed Jun 11 07:48:20 MDT 2003


Hi,

somehow my last Message got truncated. :-/

I have two seperate processes communicatinbg 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()





More information about the Twisted-Python mailing list