Re: Is it possible to use a class instance in remote methods?
Daniel Krause <m.daniel.krause-gM/[email protected]>
| Newsgroups | gmane.comp.python.pyro |
|---|---|
| Message-ID | <CAMiLiKg2chMjdrRB0dW8c4RvBExaafLxTrmpFq4EwgiMLOUubQ@mail.gmail.com> |
Hello,
I could find in the Pyro3 documentation a solution:
It is necessary to import the class into the namespace of the server-module
too.
Adding to pyrotest_server.py
from pyrotest_client.py import ClassToSend
or
from pyrotest_client.py import *
solved my initial problem.
But in the real world I am still at a dead end. I need to use a data format
named FITS (for scientific image data), and the approach above does not
help me...
Below are the sample scripts:
'''
pyrotest_server
'''
import Pyro4
from pyfits import *
from pyfits.column import Column
from pyfits.hdu.image import PrimaryHDU
from pyfits.hdu.table import BinTableHDU
class Test(object):
def set(self, class_in):
#do nothing, only to check that class_in is accepted
pass
if __name__ == '__main__':
Pyro4.config.DOTTEDNAMES = True
Pyro4.config.DETAILED_TRACEBACK = True
test = Test()
daemon=Pyro4.Daemon() # make a Pyro daemon
ns=Pyro4.locateNS() # find the name server
uri=daemon.register(test) # register as a Pyro object
ns.register("test", uri) # register the object with a name in the
name server
daemon.requestLoop()
'''
pyrotest_client.py
'''
import Pyro4
import pyfits
if __name__ == '__main__':
test = Pyro4.Proxy("PYRONAME:test")
#1st step of defining a binary table HDU (header-data-unit)
#Some basic table definition for one column
column = pyfits.Column(name='test', format='A30')
#type is used to identify the class to import on the server side
print 'type of column: ', type(column)
#2nd step of defining a binary table HDU
BinTableHDU = pyfits.new_table([column])
#type is used to identify the class to import on the server side
print type(BinTableHDU)
class_to_send = BinTableHDU
test.set(class_to_send)
I get the following console output, but I cannot make any sense out of the
traceback:
HMAC_KEY not set, protocol data may not be secure
type of column: <class 'pyfits.column.Column'>
<class 'pyfits.hdu.table.BinTableHDU'>
HMAC_KEY not set, protocol data may not be secure
Traceback (most recent call last):
File
"C:\Users\mdk\workspace\lr_control\src\lr_remote\pyrotest_client.py", lin
e 19, in <module>
test.set(class_to_send)
File "C:\Python27\lib\site-packages\pyro4-4.17-py2.7.egg\Pyro4\core.py",
line
149, in __call__
return self.__send(self.__name, args, kwargs)
File "C:\Python27\lib\site-packages\pyro4-4.17-py2.7.egg\Pyro4\core.py",
line
294, in _pyroInvoke
raise data
TypeError: __new__() takes at least 2 arguments (1 given)
Any help is very welcome, thanks
Daniel
2013/3/11 Daniel Krause <m.daniel.krause-gM/[email protected]>
> Hello,
>
> I try to use a class instance in a remote method.
>
> But so far I can only use single variables of the class instance (e.g.
> method(class.variable)) in a remote method, but I can not use the class
> instance itself (method(class) is not working).
> Maybe I try something that is not intended:
> Is it possible to use remote methods with class instances, and if yes, how?
>
> Below is some code to illustrate my problem.
>
> Daniel
>
> '''
> pyrotest_server.py
> '''
> import Pyro4
>
> class Test(object):
> def set(self, class_in):
> self.new_class = class_in
>
> if __name__ == '__main__':
> Pyro4.config.DOTTEDNAMES = True
> test = Test()
> daemon=Pyro4.Daemon() # make a Pyro daemon
> ns=Pyro4.locateNS() # find the name server
> uri=daemon.register(test) # register as a Pyro object
> ns.register("test", uri) # register the object with a name in the
> name server
> print 'test registered'
> print "Ready."
> daemon.requestLoop()
>
> console output:
> C:\Python27\lib\site-packages\pyro4-4.17-py2.7.egg\Pyro4\core.py:155:
> UserWarnin
> g: HMAC_KEY not set, protocol data may not be secure
> warnings.warn("HMAC_KEY not set, protocol data may not be secure")
> test registered
> Ready.
>
>
> '''
> pyrotest_client.py
> '''
> import Pyro4
>
> class ClassToSend(object):
> def __init__(self):
> self.var1 = "variable 1"
>
> if __name__ == '__main__':
> test = Pyro4.Proxy("PYRONAME:test")
> class_to_send = ClassToSend()
> try:
> test.set(class_to_send.var1)
> print 'test.set(class_to_send.var1) worked'
> except Exception as e:
> print 'exception on test.set(class_to_send.var1) occured: ', e
> try:
> test.set(class_to_send)
> print 'test.set(class_to_send) worked'
> except Exception as e:
> print 'exception on test.set(class_to_send) occured: ', e
> print 'done'
>
> console output:
> C:\Python27\lib\site-packages\pyro4-4.17-py2.7.egg\Pyro4\core.py:155:
> UserWarnin
> g: HMAC_KEY not set, protocol data may not be secure
> warnings.warn("HMAC_KEY not set, protocol data may not be secure")
> test.set(class_to_send.var1) worked
> exception on test.set(class_to_send) occured: 'module' object has no
> attribute
> 'ClassToSend'
> done
>
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Pyro-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyro-core