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 (49 lines) | stat: -rw-r--r-- 1,120 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
43
44
45
46
47
48
49
from __future__ import print_function
import time

import Pyro4


# set the oneway behavior to run inside a new thread, otherwise the client stalls.
# this is the default, but I've added it here just for clarification.
Pyro4.config.ONEWAY_THREADED = True


@Pyro4.expose
class Server(object):
    def __init__(self):
        self.busy = False

    @Pyro4.oneway
    def oneway_start(self, duration):
        print("start request received. Starting work...")
        self.busy = True
        for i in range(duration):
            time.sleep(1)
            print(duration - i)
        print("work is done!")
        self.busy = False

    def ready(self):
        print("ready status requested (%r)" % (not self.busy))
        return not self.busy

    def result(self):
        return "The result :)"

    def nothing(self):
        print("nothing got called, doing nothing")

    @Pyro4.oneway
    def oneway_work(self):
        for i in range(10):
            print("work work..", i+1)
            time.sleep(1)
        print("work's done!")


# main program

Pyro4.Daemon.serveSimple({
    Server: "example.oneway"
})