[Numpy-discussion] xml-rpc with numpy arrays

Uwe Schmitt rocksportrocker at googlemail.com
Tue Sep 30 14:09:33 EDT 2008


Hi,

in order to marshal numpy arrays, you can use the
tostring() method. The inverse is the fromstring()
function in numpy.
But you must know dtype and shape in order to
reconstruct your array.

Greetings, Uwe

On 30 Sep., 19:53, Brian Blais <bbl... at bryant.edu> wrote:
> Hello,
>
> I am trying to use xml-rpc to be able to run some simulations  
> remotely.  I am running into a problem with the transfer of numpy  
> arrays.  my server code looks like:
>
> #!/usr/bin/env python
> def again(x):  # test out the sending of data
>      return [x,x]
>
> from SimpleXMLRPCServer import SimpleXMLRPCServer
> SimpleXMLRPCServer.allow_reuse_address = 1
>
> server = SimpleXMLRPCServer(("", 8000))
>
> server.register_function(again)
> try:
>      print "Serving..."
>      server.serve_forever() # Start the server
> finally:
>      print "done."
>      server.server_close()
>
> my client code looks like:
>
> import numpy
> from xmlrpclib import ServerProxy
> server=ServerProxy('http://localhost:8000')
> server.again(5)  # this works
>
> b=numpy.random.rand(5,5)
>
> server.again(b)  # this gives an error
>
> this gives the error: <type 'exceptions.TypeError'>: cannot marshal  
> <type 'numpy.ndarray'> objects
>
> which seems to be a deficiency of the marshal library, or perhaps I  
> am doing something wrong.  Is there a way to fix this?  Is there  
> another approach that I should be using?
>
>                 thanks,
>
>                         Brian Blais
>
> --
> Brian Blais
> bbl... at bryant.eduhttp://web.bryant.edu/~bblais
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discuss... at scipy.orghttp://projects.scipy.org/mailman/listinfo/numpy-discussion



More information about the NumPy-Discussion mailing list