[Twisted-Python] PB and multiple apps

Jeff Grimmett grimmtooth at softhome.net
Sat Feb 15 01:05:51 EST 2003


> Have you seen doc/examples/pbecho.py and 
> doc/examples/pbechoclient.py?  They do pretty much exactly 
> this, i.e. a long-running server, and a one-shot
> client:

Yep, but there's that dreaded reactor.stop() in the client.

Good news: I figured out how to make it work. I've created a class that
I use as a mix-in for my protocol classes to utilize. The down side is
that I have to maintain two versions of the debugger OR put in some
conditional code, but the upshot is that I can now do exactly what I
needed to do with it.

class Debugger:
  def Debug (self, txt):
    self.dbtxt = txt
    pb.getObjectAt("localhost", DBPort, 30).addCallbacks(self.gotObject,
self.gotNoObject)
		
    def gotObject(self, object): 
      print 'client got object'
      object.callRemote ("DoCommand", {'Command': 'Msg',
'Msg':self.dbtxt} ).addCallback(self.gotCommand)
		
    def gotCommand(self, rc):
      print 'gotcommand',rc
      self.dbrc = rc

    def gotNoObject(reason):
      print 'gotnoobject', reason
      self.dbrc = -1

When creating the protocol, it looks like this:

 from Debug import Debugger

 class myProtocol(Protocol, Debugger):
    <stuff>

Then to send the debugging text to the other app loop:
  self.Debug(text)

Oh, there's a bit of cleanup to do but the upshot is that it does NOT
kill off the reactor running the protocol that calls it.

Off to bed...






More information about the Twisted-Python mailing list