Exemplo n.º 1
0
#!/usr/bin/env python
import sys, os
import Pyro.util

sys.path.insert(0,os.pardir)	# to find testclient.py

import testclient

# Get a proxy with attrs 
test = testclient.getproxy('attributes',True)

name = raw_input('Enter a name: ')

# new way of doing things:
# direct attribute access!

print 'current sum=',test.sum
print 'last changed by',test.changedby

test.sum = test.sum+1
test.changedby = name

print 'new sum=',test.sum

# creating some new attributes
test.newattr1 = 'new_one'
test.newattr2 = 'new_two'

print 'new attr 1=',test.newattr1
print 'new attr 2=',test.newattr2
Exemplo n.º 2
0
#!/usr/bin/env python
import sys, os

sys.path.insert(0, os.pardir)	# to find testclient.py

import testclient

fact = testclient.getproxy('factory')

print 'Local Python PID =', os.getpid()

c1=fact.create('Opel')
c2=fact.create('Ford')
c3=fact.create('Honda')

print 'Factory produced three cars (of three different brands).'
print 'Each object\'s PID is printed after its name. The PID'
print 'is different than the local Python PID above: its the PID'
print 'from the server process (the factory) that produced them!'
print '(look in the server window to see what its PID is).'
print c1.name(), 'pid=',c1.pid()
print c2.name(), 'pid=',c2.pid()
print c3.name(), 'pid=',c3.pid()


Exemplo n.º 3
0
#!/usr/bin/env python
import sys, os

sys.path.insert(0,os.pardir)		# to find testclient.py

import testclient
import Pyro.util

from excep import MyError

test = testclient.getproxy('exceptions')

print test.div(2.0,9.0)
try:
	print 2/0
except ZeroDivisionError,x:
	print 'DIVIDE BY ZERO',x
try:
	print test.div(2,0)
except ZeroDivisionError,x:
	print 'DIVIDE BY ZERO',x
try:
	result=test.error()
	print repr(result),result
except ValueError,x:
	print 'VALUERROR',x
try:
	result=test.error2()
	print repr(result),result
except ValueError,x:
	print 'VALUERROR',x
Exemplo n.º 4
0
#!/usr/bin/env python
import sys, os

sys.path.insert(0, os.pardir)	# to find testclient.py

import testclient

test = testclient.getproxy('inheritance')

print "base1.meth1? -->", test.meth1()		# should be base1.meth1
print "Fsub.meth2?  -->", test.meth2()		# should be Fsub.meth2
print "base2.meth3? -->", test.meth3()		# should be base2.meth3
print "Fsub.meth4?  -->", test.meth4()		# should be Fsub.meth4

Exemplo n.º 5
0
#!/usr/bin/env python
import sys, os
import Pyro.util

sys.path.insert(0, os.pardir)  # to find testclient.py

import testclient

# Get a proxy with attrs
test = testclient.getproxy('attributes', True)

name = raw_input('Enter a name: ')

# new way of doing things:
# direct attribute access!

print 'current sum=', test.sum
print 'last changed by', test.changedby

test.sum = test.sum + 1
test.changedby = name

print 'new sum=', test.sum

# creating some new attributes
test.newattr1 = 'new_one'
test.newattr2 = 'new_two'

print 'new attr 1=', test.newattr1
print 'new attr 2=', test.newattr2
Exemplo n.º 6
0
import sys, os

from Pyro.errors import *
import Pyro.core
import Pyro.util

sys.path.insert(0,os.pardir)	# to find testclient.py

import testclient

import agent.ShoppingAgent

Pyro.config.PYRO_MOBILE_CODE=1		# Enable mobile code

# Get a proxy with attrs 
mall = testclient.getproxy('Shop1',True)

Harry = agent.ShoppingAgent.ShoppingAgent('Harry')
Joyce = agent.ShoppingAgent.ShoppingAgent('Joyce')

try:
	print 'Harry goes shopping...'
	Harry=mall.goShopping(Harry)		# note that agent returns as result value
	Harry.result()
	print
	print 'Joyce goes shopping...'
	Joyce=mall.goShopping(Joyce)		# note that agent returns as result value
	Joyce.result()
	print
except Exception,x:
	print ''.join(Pyro.util.getPyroTraceback(x))
Exemplo n.º 7
0
#!/usr/bin/env python
import sys,os,time
import Pyro.protocol

sys.path.insert(0,os.pardir)		# to find testclient.py

import testclient
import bench

object = testclient.getproxy('benchmark')
object._setOneway('oneway')

def f1(): void=object.length('Irmen de Jong')
def f2(): void=object.timestwo(21)
def f3(): void=object.bigreply()
def f4(): void=object.manyargs(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
def f5(): void=object.noreply(99993333)
def f6(): void=object.varargs('een',2,(3,),[4])
def f7(): void=object.keywords(arg1='zork')
def f8(): void=object.echo('een',2,(3,),[4])
def f9(): void=object.meth1('stringetje')
def fa(): void=object.meth2('stringetje')
def fb(): void=object.meth3('stringetje')
def fc(): void=object.meth4('stringetje')
def fd(): void=object.bigarg('Argument'*50)
def fe(): void=object.oneway('stringetje',432423434)
def ff(): void=object.mapping( {"aap":42, "noot": 99, "mies": 987654} )

funcs = (f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe,ff)

print '-------- BENCHMARK REMOTE OBJECT ---------'
Exemplo n.º 8
0
#!/usr/bin/env python
import sys, os, random

import time
import threading

sys.path.insert(0, os.pardir)  # to find testclient.py

import testclient

count = int(raw_input('Number of parallel clients: '))

test = testclient.getproxy('multithread')

testObjects = [test]

for i in range(count - 1):
    testObjects.append(test.__copy__())

processtime = 1.0


def processing(index, proxy):
    thread = threading.currentThread()
    name = thread.getName()
    time.sleep(random.randint(1, 5))
    print 'Processing started', name
    while threading.currentThread().running:
        t1 = time.time()
        print name, "CALLING...."
        print name, proxy.process(name, processtime),
Exemplo n.º 9
0
#!/usr/bin/env python
import sys, os

from Pyro.errors import *
import Pyro.core

sys.path.insert(0, os.pardir)  # to find testclient.py
Pyro.config.PYRO_MOBILE_CODE = 1  # Enable mobile code

import testclient
import agent.ShoppingAgent

# Get a proxy with attrs
mall = testclient.getproxy('ShoppingMall', True)

import sys, os, string
import Pyro.core

try:
    # just to show what happens: try to supply some bogus code
    print 'Supplying bogus code to server... see what happens:'
    mall.remote_supply_code('crash', 'this is no python code', 333)
    print 'Server ACCEPTED!!! You should not see this!!!'
except PyroError, x:
    print 'remote_supply_code failed:', x

print

Harry = agent.ShoppingAgent.ShoppingAgent('Harry')
Harry.cashLimit(500)
Harry.shoppingList(['tv', 'mouse', 'bananas', 'boots', 'snowboard', 'goggles'])
Exemplo n.º 10
0
#!/usr/bin/env python
import sys, os

sys.path.insert(0, os.pardir)  # to find testclient.py

import testclient
import Pyro.util

from excep import MyError

test = testclient.getproxy("exceptions")

print test.div(2.0, 9.0)
try:
    print 2 / 0
except ZeroDivisionError, x:
    print "DIVIDE BY ZERO", x
try:
    print test.div(2, 0)
except ZeroDivisionError, x:
    print "DIVIDE BY ZERO", x
try:
    result = test.error()
    print repr(result), result
except ValueError, x:
    print "VALUERROR", x
try:
    result = test.error2()
    print repr(result), result
except ValueError, x:
    print "VALUERROR", x
Exemplo n.º 11
0
#!/usr/bin/env python
import sys, os

sys.path.insert(0, os.pardir)	# to find testclient.py

import testclient

obj = testclient.getproxy('hugetransfer')
#if os.name!="java":
#	object._setTimeout(4)

import time

basesize = 500000

data = 'A' * basesize

totalsize = 0
begin = time.time()
for i in range(1, 15):
	print 'transferring', basesize * i, 'bytes'
	size = obj.transfer(data * i)
	# print " reply=",size
	totalsize = totalsize + basesize * i
duration = time.time() - begin

print 'It took', duration, 'seconds to transfer', totalsize / 1024, 'kilobyte.'
print 'That is', totalsize / 1024 / duration, 'k/sec. = ', totalsize / 1024 / 1024 / duration, 'mb/sec.'

Exemplo n.º 12
0
#!/usr/bin/env python
import sys, os

sys.path.insert(0, os.pardir)  # to find testclient.py

import testclient
import Pyro.util

from excep import MyError

test = testclient.getproxy('exceptions')

print test.div(2.0, 9.0)
try:
    print 2 / 0
except ZeroDivisionError, x:
    print 'DIVIDE BY ZERO', x
try:
    print test.div(2, 0)
except ZeroDivisionError, x:
    print 'DIVIDE BY ZERO', x
try:
    result = test.error()
    print repr(result), result
except ValueError, x:
    print 'VALUERROR', x
try:
    result = test.error2()
    print repr(result), result
except ValueError, x:
    print 'VALUERROR', x
Exemplo n.º 13
0
#!/usr/bin/env python
import sys, os

sys.path.insert(0,os.pardir)	# to find testclient.py

import testclient

test = testclient.getproxy('inheritance')

print "base1.meth1? -->",test.meth1()		# should be base1.meth1
print "Fsub.meth2?  -->",test.meth2()		# should be Fsub.meth2
print "base2.meth3? -->",test.meth3()		# should be base2.meth3
print "Fsub.meth4?  -->",test.meth4()		# should be Fsub.meth4

Exemplo n.º 14
0
#!/usr/bin/env python
import sys, os, random

import time
import threading

sys.path.insert(0, os.pardir)	# to find testclient.py

import testclient

count = int(raw_input('Number of parallel clients: '))


test = testclient.getproxy('multithread')

testObjects = [test]

for i in range(count - 1):
	testObjects.append(test.__copy__())

processtime = 1.0

def processing(index, proxy):
	thread = threading.currentThread()
	name = thread.getName()
	time.sleep(random.randint(1, 5))
	print 'Processing started', name
	while threading.currentThread().running:
		t1 = time.time()
		print name, "CALLING...."
		print name, proxy.process(name, processtime),
Exemplo n.º 15
0
import sys, os

from Pyro.errors import *
import Pyro.core
import Pyro.util

sys.path.insert(0, os.pardir)  # to find testclient.py

import testclient

import agent.ShoppingAgent

Pyro.config.PYRO_MOBILE_CODE = 1  # Enable mobile code

# Get a proxy with attrs
mall = testclient.getproxy('Shop1', True)

Harry = agent.ShoppingAgent.ShoppingAgent('Harry')
Joyce = agent.ShoppingAgent.ShoppingAgent('Joyce')

try:
    print 'Harry goes shopping...'
    Harry = mall.goShopping(Harry)  # note that agent returns as result value
    Harry.result()
    print
    print 'Joyce goes shopping...'
    Joyce = mall.goShopping(Joyce)  # note that agent returns as result value
    Joyce.result()
    print
except Exception, x:
    print ''.join(Pyro.util.getPyroTraceback(x))
Exemplo n.º 16
0
#!/usr/bin/env python
import sys, os

from Pyro.errors import *
import Pyro.core

sys.path.insert(0,os.pardir)	# to find testclient.py
Pyro.config.PYRO_MOBILE_CODE=1		# Enable mobile code

import testclient
import agent.ShoppingAgent


# Get a proxy with attrs
mall = testclient.getproxy('ShoppingMall',True)

import sys, os, string
import Pyro.core

try:
	# just to show what happens: try to supply some bogus code
	print 'Supplying bogus code to server... see what happens:'
	mall.remote_supply_code('crash','this is no python code',333)
	print 'Server ACCEPTED!!! You should not see this!!!'
except PyroError,x:
	print 'remote_supply_code failed:',x

print


Harry = agent.ShoppingAgent.ShoppingAgent('Harry')
Exemplo n.º 17
0
#!/usr/bin/env python
import sys, os

sys.path.insert(0, os.pardir)  # to find testclient.py

import testclient

obj = testclient.getproxy('hugetransfer')
#if os.name!="java":
#	object._setTimeout(4)

import time

basesize = 500000

data = 'A' * basesize

totalsize = 0
begin = time.time()
for i in range(1, 15):
    print 'transferring', basesize * i, 'bytes'
    size = obj.transfer(data * i)
    # print " reply=",size
    totalsize = totalsize + basesize * i
duration = time.time() - begin

print 'It took', duration, 'seconds to transfer', totalsize / 1024, 'kilobyte.'
print 'That is', totalsize / 1024 / duration, 'k/sec. = ', totalsize / 1024 / 1024 / duration, 'mb/sec.'