~ubuntu-branches/debian/sid/pyro/sid

« back to all changes in this revision

Viewing changes to examples/simple/client_thread.py

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz, Sandro Tosi, Bernd Zeimetz
  • Date: 2009-05-25 14:26:23 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090525142623-31cqgb2pdff6c1az
Tags: 3.9.1-1
[ Sandro Tosi ]
* debian/control
  - switch Vcs-Browser field to viewsvn

[ Bernd Zeimetz ]
* New upstream release.
* debian/patches/usr-bin-env-location.dpatch:
  - Dropping patch, applied usptream. 
* debian/control, debian/rules:
  - Dropping dpatch build-dep and include, not needed anymore. 
* Switching to python-support and dh 7.
* Bumping Standards-Version to 3.8.1. 
* Dropping maintainer scripts, dh creates them properly. 
* Adding missing ${misc:Depends}. 
* Fix several file permissions in the examples package.
* Add symlink to the actual docu in pyro-examples. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
2
 
 
3
 
import Pyro.util
4
 
import Pyro.core
5
 
import threading
6
 
import time
7
 
import copy
8
 
 
9
 
def myThread(proxy):
10
 
        print "inside myThread().. calling mul...:",
11
 
        try:
12
 
                print proxy.mul(222,10)
13
 
        except Exception,x:
14
 
                print ">>Exception in myThread:",x
15
 
        print "done in myThread()."
16
 
 
17
 
 
18
 
Pyro.core.initClient()
19
 
 
20
 
test = Pyro.core.getAttrProxyForURI("PYRONAME://:test.simple")
21
 
 
22
 
print "Got a new proxy, first call is from a different thread (should work!)"
23
 
thread=threading.Thread(target=myThread, args=(test,) )
24
 
thread.start()
25
 
time.sleep(1)
26
 
print "Now calling it from main thread (should fail)"
27
 
try:
28
 
        print test.mul(111,9)
29
 
except Exception,x:
30
 
        print "(expected) exception:",x
31
 
 
32
 
# create a copy of the proxy and use that instead. Should work.
33
 
print "Calling a copy of the proxy, that should work."
34
 
test2 = copy.copy(test)
35
 
print test2.mul(111,9)
36
 
 
37
 
# release the original proxy, and try again.
38
 
# this time it should work, because it is us that reconnect it...
39
 
print "releasing original proxy and calling again (should work now)"
40
 
test._release()
41
 
print test.mul(111,9)
42
 
 
43
 
 
44
 
 
45
 
# do again from a thread. This should fail now
46
 
print "Calling from a thread. Should now get exception about proxy sharing!"
47
 
thread=threading.Thread(target=myThread, args=(test,) )
48
 
thread.start()
49
 
time.sleep(1)
50
 
 
51
 
# do again from a thread, but this time transfer ownership
52
 
# after that, when *we* attempt to call it it should fail instead... :)
53
 
print "\nCall again from a thread, but with thransfered ownership. No exception should occur this time."
54
 
print "Transfer ownership to thread..."
55
 
thread=threading.Thread(target=myThread, args=(test,) )
56
 
test._transferThread(thread)  # usually, the thread itself calls this.
57
 
thread.start()  # should work now
58
 
time.sleep(1)
59
 
 
60
 
print "\n\ncalling ourselves again...(should get exception now):"
61
 
print test.mul(44,55)    # should fail now
62
 
 
63
 
print "end"