File: bounce_client.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 (47 lines) | stat: -rw-r--r-- 968 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
40
41
42
43
44
45
46
47
#!/usr/bin/env python

import time, random
import Pyro.core
import Pyro.naming
from Pyro.errors import *
from threading import Thread
import bouncer

abort=0

def PyroLoop(daemon):
	global abort
	print 'Pyro daemon loop thread is running.'
	daemon.requestLoop(lambda: not abort) 
	print 'Pyro daemon loop thread is exiting.'


def main():
	global abort
	Pyro.core.initServer()
	Pyro.core.initClient()
	daemon = Pyro.core.Daemon()
	NS = Pyro.naming.NameServerLocator().getNS()
	daemon.useNameServer(NS)

	bounceObj = bouncer.Bouncer("Client")
	daemon.connect(bounceObj)  # callback object

	server = NS.resolve(':test.bouncer').getProxy()

	# create a thread that handles callback requests
	thread=Thread(target=PyroLoop, args=(daemon,))
	thread.start()

	print 'Calling server from main (a single call)...'
	result = server.process(["hello"], bounceObj.getProxy())
	print 'Result=',result

	abort=1
	thread.join()
	print 'Exiting.'


if __name__=='__main__':
	main()