File: server.py

package info (click to toggle)
pyro5 5.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,124 kB
  • sloc: python: 14,328; makefile: 161; sh: 66; javascript: 62
file content (49 lines) | stat: -rw-r--r-- 1,013 bytes parent folder | download
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
43
44
45
46
47
48
49
import time
from Pyro5.api import expose, serve, config


if config.ITER_STREAMING:
    print("Note: iter-streaming has been enabled in the Pyro config.")
else:
    print("Note: iter-streaming has not been enabled in the Pyro config (PYRO_ITER_STREAMING).")


@expose
class Streamer(object):
    def list(self):
        return [1, 2, 3, 4, 5, 6, 7, 8, 9]

    def iterator(self):
        return iter([1, 2, 3, 4, 5, 6, 7, 8, 9])

    def generator(self):
        i = 1
        while i < 10:
            yield i
            i += 1

    def slow_generator(self):
        i = 1
        while i < 10:
            time.sleep(0.5)
            yield i
            i += 1

    def fibonacci(self):
        a, b = 0, 1
        while True:
            yield a
            a, b = b, a + b

    @property
    def prop_iter(self):
        return iter([1,2,3,4,5,6,7,8,9,10])

    @property
    def prop_generator(self):
        return (x for x in range(10))


serve({
        Streamer: "example.streamer"
    }, use_ns=False)