~ubuntu-branches/ubuntu/oneiric/pyro/oneiric

« back to all changes in this revision

Viewing changes to examples/timeout/timeout2.py

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz
  • Date: 2007-09-01 23:12:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070901231252-veufo1dqva5oipo1
Tags: 3.7-1
* Adopting the package in the name of the Python Modules Team
  (Closes: #439048)
  - Thanks to Alexandre Fayolle and Jérémy Bobbio for the previous NMUs
    (Closes: #216731, #377680, #391808)
* New upstream version
* debian/watch:
  - Adding file
* debian/control:
  - Reflecting maintainer change
  - Adding XS-Vcs-Svn and XS-Vcs-Browser fields
  - Moving python to Build-Depends because it's used in the clean target
  - Adding dpatch to Build-Depends
  - Putting pyro-doc into the doc Section
* debian/semantic.cache:
  - Removing file, not needed for packaging pyro
* debian/setup.cfg:
  - Adding file to configure upstream's very special setup.py
* debian/rules:
  - Fixing build process to use debian/setup.cfg
  - Adding dpatch targets/include
* debian/README.Debian:
  - Removing file, explanation not needed anymore
* debian/NEWS.Debian:
  - Adding file, explaining upstream's change in the script names
* debian/patches:
  - Adding patch to cleanup/fix shebangs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import time
 
2
import Pyro.core
 
3
import Pyro.naming
 
4
from Pyro.errors import NamingError
 
5
from threading import Thread
 
6
 
 
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
 
13
        self.setDaemon(True)
 
14
 
 
15
    def run(self):
 
16
        self.__tIsRunning = True
 
17
        while self.__tIsRunning:
 
18
            time.sleep(.1)
 
19
            self.__oDaemon.handleRequests(3)
 
20
        self.__oDaemon.shutdown()
 
21
        self.__tIsStopped = True
 
22
        print "server stopped."
 
23
 
 
24
    def stop(self):
 
25
        self.__tIsRunning = False
 
26
 
 
27
    def isStopped(self):
 
28
        return self.__tIsStopped
 
29
 
 
30
 
 
31
class MyObject(Pyro.core.ObjBase):
 
32
    def test(self):
 
33
        print 'test called'
 
34
 
 
35
Pyro.core.initServer()
 
36
 
 
37
oNs = Pyro.naming.NameServerLocator().getNS()
 
38
oDaemon = Pyro.core.Daemon()
 
39
oDaemon.useNameServer(oNs)
 
40
 
 
41
 
 
42
strTag = 'timeout_example'
 
43
try:
 
44
    oNs.unregister(strTag)
 
45
except NamingError:
 
46
    pass
 
47
 
 
48
oObj = MyObject()
 
49
strUri = oDaemon.connect(oObj, strTag)
 
50
 
 
51
oServer = MySimpleServer(oDaemon)
 
52
oServer.start()
 
53
 
 
54
oProxy = Pyro.core.getProxyForURI(strUri)
 
55
# not setting timeout this time:  oProxy._setTimeout(4)
 
56
 
 
57
print 'calling remote method on live proxy.'
 
58
oProxy.test()
 
59
print 'success.'
 
60
 
 
61
print "stopping server..."
 
62
oServer.stop()
 
63
while not oServer.isStopped():
 
64
    time.sleep(.1)
 
65
 
 
66
print
 
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)
 
72
oProxy.test()
 
73
print 'This should not be shown!!! The method call should have blocked indefinitely!'