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

Stefan Fleiter sf.lists at web.de
Fri Jun 13 11:44:53 EDT 2003


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, 


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
     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
     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)

if __name__ == '__main__':
     import listener
     ab_app = app.Application("ABListener")
     ab_app.listenTCP(8848, pb.BrokerFactory(ABListener()))

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

def doDir():
     mr = MessageReceiver()
     c = CComHandler(mr)
     pb.getObjectAt("localhost", 8848, 30).addCallback(c.gotObject)

if __name__ == "__main__":
     machine = 'mymachine'
     packages = [('myPackage', 'myVersion')]

More information about the Twisted-Python mailing list