Hi Tomer,
I rewrite some code to show the problem, I described below:
-s1.py : the service server to get array info asked by client.py
-s2.py: the gui: show information send by client.py
-client.py: get information from any device/source info, compile and use an
remote GUI to show info
Again, the aim of this project is to get infos from devices servers,
compile info in client.py then send infos to some gui server.
Clearly this example have no sense, but only show the error about the
access to the method tostring().
Hope it helps !
####s1.py
'''
Server 1 : serve an array
'''
import rpyc,sys
from rpyc.utils.server import ThreadedServer
import numpy as np
class ArrayService(rpyc.Service):
def exposed_GetArray(self):
array=np.array([[1,2,3],[4,5,6]])
return array
if __name__ == "__main__":
if len(sys.argv)==2: port = int(sys.argv[1])
else: port = 2222
server = ThreadedServer(ArrayService, port =
port,hostname="localhost",protocol_config={'allow_all_attrs':True})
server.start()
####s2.py
'''
Server 2 Gui for Array
'''
import rpyc,sys
from rpyc.utils.server import ThreadedServer
#import numpy as np
import numpy as np
class WatchService(rpyc.Service):
def exposed_ShowArray(self,array):
print array.tostring() #it fails!
return True
if __name__ == "__main__":
if len(sys.argv)==2: port = int(sys.argv[1])
else: port = 2223
server = ThreadedServer(WatchService, port =
port,hostname="localhost",protocol_config={'allow_all_attrs':True})
server.start()
#####client.py
# -*- coding: UTF-8 -*-
'''
Client get from Server1 (s1.py) to Server2 (s2.py)
'''
import rpyc,time,subprocess,os,signal
proc=[]
proc.append(subprocess.Popen(r"python .\s1.py "+str(2222), bufsize=-1,
creationflags = subprocess.CREATE_NEW_CONSOLE).pid)
proc.append(subprocess.Popen(r"python .\s2.py "+str(2223), bufsize=-1,
creationflags = subprocess.CREATE_NEW_CONSOLE).pid)
time.sleep(1)
Server1=rpyc.connect("localhost",2222)
Server2=rpyc.connect("localhost",2223)
array=Server1.root.GetArray()
print array.tostring() #it works!
Server2.root.ShowArray(array)
for i in range(len(proc)):
time.sleep(0.1)
print "kill ",proc[i],' ',os.kill(proc[i],signal.SIGTERM )==None
regards,
-damien
Le lundi 25 juin 2012 17:54:15 UTC+2, Tomer Filiba a écrit :
>
> you'd have to provide a code snippet that reconstructs the problem.
>
> but if ultimately need to copy the ndarray from one process to another
> (passing it by value),
> you can use obtains. see
> http://rpyc.sourceforge.net/api/utils_classic.html#rpyc.utils.classic.obtain
>
> -----------------------------------------------------------------
>
> *Tomer Filiba*
> tomerfiliba.com <http://www.facebook.com/tomerfiliba>
> <http://il.linkedin.com/in/tomerfiliba>
>
>
>
> On Mon, Jun 25, 2012 at 3:35 PM, baco <damien> wrote:
>
>> Hi all,
>> I have a <netref class 'numpy.ndarray'> object (server side) and I can't
>> access to any of method (in particular the .tostring()).
>> Data from this object is ok, but need to have the 'real' numpy.ndarray
>> from my client, to use it.
>> thanks for help
>> -baco
>>
>
># -*- coding: UTF-8 -*-
'''
Client get from Server1 (s1.py) to Server2 (s2.py)
'''
import rpyc,time,subprocess,os,signal
proc=[]
proc.append(subprocess.Popen(r"python .\s1.py "+str(2222), bufsize=-1, creationflags = subprocess.CREATE_NEW_CONSOLE).pid)
proc.append(subprocess.Popen(r"python .\s2.py "+str(2223), bufsize=-1, creationflags = subprocess.CREATE_NEW_CONSOLE).pid)
time.sleep(1)
Server1=rpyc.connect("localhost",2222)
Server2=rpyc.connect("localhost",2223)
array=Server1.root.GetArray()
print array.tostring() #it works!
Server2.root.ShowArray(array)
for i in range(len(proc)):
time.sleep(0.1)
print "kill ",proc[i],' ',os.kill(proc[i],signal.SIGTERM )==None'''
Server 1 : serve an array
'''
import rpyc,sys
from rpyc.utils.server import ThreadedServer
import numpy as np
class ArrayService(rpyc.Service):
def exposed_GetArray(self):
array=np.array([[1,2,3],[4,5,6]])
return array
if __name__ == "__main__":
if len(sys.argv)==2: port = int(sys.argv[1])
else: port = 2222
server = ThreadedServer(ArrayService, port = port,hostname="localhost",protocol_config={'allow_all_attrs':True})
server.start()
'''
Server 2 Gui for Array
'''
import rpyc,sys
from rpyc.utils.server import ThreadedServer
#import numpy as np
import numpy as np
class WatchService(rpyc.Service):
def exposed_ShowArray(self,array):
print array.tostring() #it fails!
return True
if __name__ == "__main__":
if len(sys.argv)==2: port = int(sys.argv[1])
else: port = 2223
server = ThreadedServer(WatchService, port = port,hostname="localhost",protocol_config={'allow_all_attrs':True})
server.start()