[Twisted-Python] question on pb-client

Hello, I'm new to Twisted and want to use the Perspective Broker. I read the howto pages of the web site, but I coundn't find answer of my question. I'm testing the echo server/clinet (pbsimpleserver.py and pbsimpleclient.py). I can successfully run them, but if I change the client to the following, the result seems strange. --- from twisted.spread import pb from twisted.internet import reactor from twisted.python import util factory = pb.PBClientFactory() reactor.connectTCP("localhost", 8789, factory) def test(): d = factory.getRootObject() d.addCallback(lambda object: object.callRemote("echo", "hello network")) d.addCallback(lambda echo: 'server echoed: '+echo) d.addErrback(lambda reason: 'error: '+str(reason.value)) d.addCallback(util.println) d.addCallback(lambda _: reactor.stop()) reactor.run() return # calls test twice test() test() --- If I execute this client code, the client doesn't finish running. And the server prints out "echoing: hello network" only once. So, it seems that the client failed to get the root object, or to call the remote method. What's the problem? I can't get the root object multiple times? Thanks, naoya

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 The problem you have is that reactor.run() never returns. It's the main-loop. On Tuesday 21 September 2004 09:10 pm, Naoya Maruyama wrote:
- -- UC - -- Open Source Solutions 4U, LLC 2570 Fleetwood Drive Phone: +1 650 872 2425 San Bruno, CA 94066 Cell: +1 650 302 2405 United States Fax: +1 650 872 2417 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQFBUQDajqGXBvRToM4RAnclAJ9ByucFmmEwRwEFSWax29p4jqh+BQCgt5NM WY8m9UwJRGFCCtjSa+r0SV8= =M2T2 -----END PGP SIGNATURE-----

On Tue, 21 Sep 2004 23:10:38 -0500, Naoya Maruyama <naoya@matsulab.is.titech.ac.jp> wrote:
Just call reactor.run() once, at the very end of this script, and only call reactor.stop() once, as a callback to the second test() call. So, in summary, make test() *not* addCallback a reactor.stop, make it _not_ call reactor.run, and change your second test() call to test().addCallback(lambda _: reactor.stop()) and then put reactor.run() after that.
-- Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://radix.twistedmatrix.com

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 The problem you have is that reactor.run() never returns. It's the main-loop. On Tuesday 21 September 2004 09:10 pm, Naoya Maruyama wrote:
- -- UC - -- Open Source Solutions 4U, LLC 2570 Fleetwood Drive Phone: +1 650 872 2425 San Bruno, CA 94066 Cell: +1 650 302 2405 United States Fax: +1 650 872 2417 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQFBUQDajqGXBvRToM4RAnclAJ9ByucFmmEwRwEFSWax29p4jqh+BQCgt5NM WY8m9UwJRGFCCtjSa+r0SV8= =M2T2 -----END PGP SIGNATURE-----

On Tue, 21 Sep 2004 23:10:38 -0500, Naoya Maruyama <naoya@matsulab.is.titech.ac.jp> wrote:
Just call reactor.run() once, at the very end of this script, and only call reactor.stop() once, as a callback to the second test() call. So, in summary, make test() *not* addCallback a reactor.stop, make it _not_ call reactor.run, and change your second test() call to test().addCallback(lambda _: reactor.stop()) and then put reactor.run() after that.
-- Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://radix.twistedmatrix.com
participants (4)
-
Christopher Armstrong
-
exarkun@divmod.com
-
Naoya Maruyama
-
Uwe C. Schroeder