File: server.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 (33 lines) | stat: -rw-r--r-- 899 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
# The server that doesn't use the Name Server.

from __future__ import print_function
import os

import Pyro4


class QuoteGen(object):
    @Pyro4.expose
    def quote(self):
        try:
            quote = os.popen('fortune').read()
            if len(quote) > 0:
                return quote
            return "This system cannot provide you a good fortune, install 'fortune'"
        except:
            return "This system knows no witty quotes :-("


with Pyro4.core.Daemon() as daemon:
    quote1 = QuoteGen()
    quote2 = QuoteGen()

    uri1 = daemon.register(quote1)  # let Pyro create a unique name for this one
    uri2 = daemon.register(quote2, "example.quotegen")  # provide a logical name ourselves

    print("QuoteGen is ready, not using the Name Server.")
    print("You can use the following two URIs to connect to me:")
    print(uri1)
    print(uri2)

    daemon.requestLoop()