File: server.py

package info (click to toggle)
pyro 1%3A3.14-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,048 kB
  • ctags: 1,988
  • sloc: python: 11,194; xml: 128; sh: 52; makefile: 28
file content (39 lines) | stat: -rw-r--r-- 932 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env python
import Pyro.core
import Pyro.naming
import time

class server(Pyro.core.ObjBase):
    def __init__(self):
        Pyro.core.ObjBase.__init__(self)
        self.busy=False
    def start(self):
        print "start request received. Starting work..."
        self.busy=True
        for i in range(10):
            time.sleep(1)
            print 10-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 :)"
      

######## main program

Pyro.config.PYRO_ONEWAY_THREADED = True			# try setting this to False and see what happens in the client

Pyro.core.initServer()

ns=Pyro.naming.NameServerLocator().getNS()

daemon=Pyro.core.Daemon()
daemon.useNameServer(ns)

uri=daemon.connect(server(),"oneway")

print "Server is ready."
daemon.requestLoop()