File: client2.py

package info (click to toggle)
pyro4 4.82-2
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 2,528 kB
  • sloc: python: 17,736; makefile: 169; sh: 113; javascript: 62
file content (42 lines) | stat: -rw-r--r-- 1,219 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from __future__ import print_function
import logging
import sys
import Pyro4


# initialize the logger so you can see what is happening with the callback exception message:
logging.basicConfig(stream=sys.stderr, format="[%(asctime)s,%(name)s,%(levelname)s] %(message)s")
log = logging.getLogger("Pyro4")
log.setLevel(logging.WARNING)


class CallbackHandler(object):
    def crash(self):
        a = 1
        b = 0
        return a // b

    @Pyro4.expose
    def call1(self):
        print("\n\ncallback 1 received from server!")
        print("going to crash - you won't see the exception here, only on the server")
        return self.crash()

    @Pyro4.expose
    @Pyro4.callback
    def call2(self):
        print("\n\ncallback 2 received from server!")
        print("going to crash - but you will see the exception here too")
        return self.crash()


daemon = Pyro4.core.Daemon()
callback = CallbackHandler()
daemon.register(callback)

with Pyro4.core.Proxy("PYRONAME:example.callback2") as server:
    server.doCallback(callback)   # this is a oneway call, so we can continue right away

print("waiting for callbacks to arrive...")
print("(ctrl-c/break the program once it's done)")
daemon.requestLoop()