[Twisted-Python] Newbie Problem
This is probably something simple. I'm having some trouble with this little bit of code below. I start it up once as a server, then a second time as the client connecting to localhost. However, it never actually seems to connect. Both sides just wait indefinitely. I'm a bit stuck as to how to debug this, so if someone has a solution for me and could tell me how I would have figured it out, that would be great! Thanks, Damon import sys import optparse import zope.interface from twisted.spread import pb from twisted.internet import reactor from twisted.internet import interfaces from twisted.python import util class ConsoleInput(object): zope.interface.implements(interfaces.IReadDescriptor) def fileno(self): return 0 def connectionLost(self, reason): print "Lost connection because %s" % reason def doRead(self): d = self.root.callRemote("echo", sys.stdin.readline().strip()) def setRoot(self, root): print "got root" self.myEchoer = Echoer() self.root = root self.root.callRemote('GiveReference', self.myEchoer) def logPrefix(self): return 'ConsoleInput' class Echoer(pb.Root): def remote_echo(self, st): print 'echoing:', st return st def remote_GiveReference(self, ref): self.client_ref = ref def main(): parser = optparse.OptionParser() parser.add_option('--host', dest='host', help='Host to connect to.') options, args = parser.parse_args() ci = ConsoleInput() reactor.addReader(ci) if options.host: host = options.host factory = pb.PBClientFactory() print "Connecting to %s..." % host reactor.connectTCP(host, 8789, pb.PBClientFactory()) d = factory.getRootObject() d.addCallback(ci.setRoot) d.addErrback(lambda reason: "error %s" % reason.value) d.addCallback(util.println) else: print "Listening..." root = Echoer() factory = pb.PBServerFactory(root) reactor.listenTCP(8789, factory) reactor.run() if __name__ == '__main__': main() __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
On Tue, 12 Sep 2006 21:11:30 -0700 (PDT), Damon Kohler <damonkohler@yahoo.com> wrote:
This is probably something simple. I'm having some trouble with this little bit of code below. I start it up once as a server, then a second time as the client connecting to localhost. However, it never actually seems to connect. Both sides just wait indefinitely. I'm a bit stuck as to how to debug this, so if someone has a solution for me and could tell me how I would have figured it out, that would be great!
Most likely the problem is sys.stdin.readline(). I suggest taking a look at twisted.internet.stdio as a way to eliminate your ConsoleInput class and the uses of the reactor-private method addReader(). If I were going to try to track down the cause of the hang, I'd probably start with strace to see where the processes are waiting. Jean-Paul
Thanks for the help. Unfortuantely, I'm still stuck. I'm on OS X and so I'm using ktrace. So far, it hasn't given me much insight. Also, it doesn't appear to be the sys.stdin call causing the trouble since I can replace that with just a string and get the same results. Any other ideas? Damon --- Jean-Paul Calderone <exarkun@divmod.com> wrote:
On Tue, 12 Sep 2006 21:11:30 -0700 (PDT), Damon Kohler <damonkohler@yahoo.com> wrote:
This is probably something simple. I'm having some trouble with this little bit of code below. I start it up once as a server, then a second time as the client connecting to localhost. However, it never actually seems to connect. Both sides just wait indefinitely. I'm a bit stuck as to how to debug this, so if someone has a solution for me and could tell me how I would have figured it out, that would be great!
Most likely the problem is sys.stdin.readline(). I suggest taking a look at twisted.internet.stdio as a way to eliminate your ConsoleInput class and the uses of the reactor-private method addReader().
If I were going to try to track down the cause of the hang, I'd probably start with strace to see where the processes are waiting.
Jean-Paul
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Whoops. Found the problem. Wasn't using the client factory I created and instead used a new factory in the reactor call :( --- Damon Kohler <damonkohler@yahoo.com> wrote:
Thanks for the help. Unfortuantely, I'm still stuck. I'm on OS X and so I'm using ktrace. So far, it hasn't given me much insight. Also, it doesn't appear to be the sys.stdin call causing the trouble since I can replace that with just a string and get the same results. Any other ideas?
Damon
--- Jean-Paul Calderone <exarkun@divmod.com> wrote:
This is probably something simple. I'm having some trouble with this
On Tue, 12 Sep 2006 21:11:30 -0700 (PDT), Damon Kohler <damonkohler@yahoo.com> wrote: little bit
of code below. I start it up once as a server, then a second time as the client connecting to localhost. However, it never actually seems to connect. Both sides just wait indefinitely. I'm a bit stuck as to how to debug this, so if someone has a solution for me and could tell me how I would have figured it out, that would be great!
Most likely the problem is sys.stdin.readline(). I suggest taking a look at twisted.internet.stdio as a way to eliminate your ConsoleInput class and the uses of the reactor-private method addReader().
If I were going to try to track down the cause of the hang, I'd probably start with strace to see where the processes are waiting.
Jean-Paul
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
participants (2)
-
Damon Kohler -
Jean-Paul Calderone