~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/historic/2003/pycon/pb/pb-client1.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python
 
2
 
 
3
from twisted.spread import pb
 
4
from twisted.internet import reactor
 
5
 
 
6
class Client:
 
7
    def connect(self):
 
8
        deferred = pb.getObjectAt("localhost", 8800, 30)
 
9
        deferred.addCallbacks(self.got_obj, self.err_obj)
 
10
        # when the Deferred fires (i.e. when the connection is established and
 
11
        # we receive a reference to the remote object), the 'got_obj' callback
 
12
        # will be run
 
13
        
 
14
    def got_obj(self, obj):
 
15
        print "got object:", obj
 
16
        self.server = obj
 
17
        print "asking it to add"
 
18
        def2 = self.server.callRemote("add", 1, 2)
 
19
        def2.addCallbacks(self.add_done, self.err)
 
20
        # this Deferred fires when the method call is complete
 
21
        
 
22
    def err_obj(self, reason):
 
23
        print "error getting object", reason
 
24
        self.quit()
 
25
 
 
26
    def add_done(self, result):
 
27
        print "addition complete, result is", result
 
28
        print "now trying subtract"
 
29
        d = self.server.callRemote("subtract", 5, 12)
 
30
        d.addCallbacks(self.sub_done, self.err)
 
31
 
 
32
    def err(self, reason):
 
33
        print "Error running remote method", reason
 
34
        self.quit()
 
35
 
 
36
    def sub_done(self, result):
 
37
        print "subtraction result is", result
 
38
        self.quit()
 
39
        
 
40
    def quit(self):
 
41
        print "shutting down"
 
42
        reactor.stop()
 
43
        
 
44
c = Client()
 
45
c.connect()
 
46
reactor.run()