~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to doc/howto/listings/pb/exc_client.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-01-16 19:56:10 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060116195610-ykmxbia4mnnod9o2
Tags: 2.1.0-0ubuntu2
debian/copyright: Include copyright for python 2.3; some 2.3 files
are included in the upstream tarball, but not in the binary packages.

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
def main():
 
7
    factory = pb.PBClientFactory()
 
8
    reactor.connectTCP("localhost", 8800, factory)
 
9
    d = factory.getRootObject()
 
10
    d.addCallbacks(got_obj)
 
11
    reactor.run()
 
12
 
 
13
def got_obj(obj):
 
14
    # change "broken" into "broken2" to demonstrate an unhandled exception
 
15
    d2 = obj.callRemote("broken")
 
16
    d2.addCallback(working)
 
17
    d2.addErrback(broken)
 
18
 
 
19
def working():
 
20
    print "erm, it wasn't *supposed* to work.."
 
21
    
 
22
def broken(reason):
 
23
    print "got remote Exception"
 
24
    # reason should be a Failure (or subclass) holding the MyError exception
 
25
    print " .__class__ =", reason.__class__
 
26
    print " .getErrorMessage() =", reason.getErrorMessage()
 
27
    print " .type =", reason.type
 
28
    reactor.stop()
 
29
 
 
30
main()