Python: xmlrpc from memory when uploading binaries

I got this simple xmlrpc server script written in python. I have limited the memory to 512mb to simulate the environment the script will run in.

import SimpleXMLRPCServer
import resource

MEMORY_LIMIT = 512
resource.setrlimit(resource.RLIMIT_AS, (MEMORY_LIMIT * 1048576L, -1L))

class Functions:
  def foo(self, file):
    print "received file"

server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000))
server.allow_none = True
server.register_instance(Functions())
server.serve_forever()

      

Then I got this client script:

import xmlrpclib
import sys

client = xmlrpclib.Server('http://localhost:8000')

file = open(sys.argv[1], 'r')
binary = xmlrpclib.Binary(file.read())

client.foo(binary)

      

When I upload a file from 20mb, I get the following exception:

xmlrpclib.Fault: <Fault 1: "<type 'exceptions.MemoryError'>:">

      

Why can't I send a 10mb file to a server with 512MB of memory?

+3


source to share





All Articles