~justin-fathomdb/nova/justinsb-openstack-api-volumes

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/core/howto/listings/pb/exc_client.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/env python
 
2
 
 
3
# Copyright (c) 2009 Twisted Matrix Laboratories.
 
4
# See LICENSE for details.
 
5
 
 
6
from twisted.spread import pb
 
7
from twisted.internet import reactor
 
8
 
 
9
def main():
 
10
    factory = pb.PBClientFactory()
 
11
    reactor.connectTCP("localhost", 8800, factory)
 
12
    d = factory.getRootObject()
 
13
    d.addCallbacks(got_obj)
 
14
    reactor.run()
 
15
 
 
16
def got_obj(obj):
 
17
    # change "broken" into "broken2" to demonstrate an unhandled exception
 
18
    d2 = obj.callRemote("broken")
 
19
    d2.addCallback(working)
 
20
    d2.addErrback(broken)
 
21
 
 
22
def working():
 
23
    print "erm, it wasn't *supposed* to work.."
 
24
    
 
25
def broken(reason):
 
26
    print "got remote Exception"
 
27
    # reason should be a Failure (or subclass) holding the MyError exception
 
28
    print " .__class__ =", reason.__class__
 
29
    print " .getErrorMessage() =", reason.getErrorMessage()
 
30
    print " .type =", reason.type
 
31
    reactor.stop()
 
32
 
 
33
main()