4
from Pyro.errors import NamingError
5
from threading import Thread
7
class MySimpleServer(Thread):
8
def __init__(self, daemon):
9
super(MySimpleServer, self).__init__()
10
self.__oDaemon = daemon
11
self.__tIsRuning = False
12
self.__tIsStopped = False
16
self.__tIsRunning = True
17
while self.__tIsRunning:
19
self.__oDaemon.handleRequests(3)
20
self.__oDaemon.shutdown()
21
self.__tIsStopped = True
22
print "server stopped."
25
self.__tIsRunning = False
28
return self.__tIsStopped
31
class MyObject(Pyro.core.ObjBase):
35
Pyro.core.initServer()
37
oNs = Pyro.naming.NameServerLocator().getNS()
38
oDaemon = Pyro.core.Daemon()
39
oDaemon.useNameServer(oNs)
42
strTag = 'timeout_example'
44
oNs.unregister(strTag)
49
strUri = oDaemon.connect(oObj, strTag)
51
oServer = MySimpleServer(oDaemon)
54
oProxy = Pyro.core.getProxyForURI(strUri)
55
# not setting timeout this time: oProxy._setTimeout(4)
57
print 'calling remote method on live proxy.'
61
print "stopping server..."
63
while not oServer.isStopped():
67
print 'calling remote method on stale proxy.'
68
print 'as we did not specify a timeout, this should block indefinitely.'
69
print '(press ctrl-c or ctrl-break to abort the program)'
70
oProxy = Pyro.core.getProxyForURI(strUri)
71
# not setting timeout this time: oProxy._setTimeout(4)
73
print 'This should not be shown!!! The method call should have blocked indefinitely!'