[Twisted-Python] twisted.web.server and memory
Lenny G Arbage
alengarbage at yahoo.com
Mon Mar 14 13:13:06 EST 2005
Run the following web server (memoryhogserver.py) and
load the provided form (post.html) into a browser of
your choice and choose a large file (~100MB) to
submit. Notice the memory usage of the python process
(on my machine, around 150MB resident).
memoryhogserver.py:
from twisted.web.resource import Resource
from twisted.web import server, resource
from twisted.internet import reactor
import os
class ROOT(Resource):
def __init__(self):
Resource.__init__(self)
def getChild(self, name, request):
if name == "":
return self
return Resource.getChild(self, name, request)
def render_GET(self, request):
return "<html>root dir</hrml>"
class UPLOAD(ROOT):
def render_POST(self, request):
f = open("/tmp/testfile","wb")
f.write(request.args.get('filename')[0])
f.close()
return "<html>upload successful</html>"
def render_GET(self, request):
return "'upload' must use POST"
if __name__ == '__main__':
root = ROOT()
root.putChild('upload',UPLOAD())
site = server.Site(root)
reactor.listenTCP(7000, site)
print "webserver listening on port 7000"
reactor.run()
post.html:
<html>
<form method="POST" enctype="multipart/form-data"
action="http://localhost:7000/upload">
<input type="file" name="filename">
<input type="submit">
</form>
</html>
(all in the spirit of replying to my own posts :)
-- Lenny G.
--- Lenny G Arbage <alengarbage at yahoo.com> wrote:
>
> A couple of questions about twisted.web server's
> memory management:
...
> If a code snippet that reproduces the above would
> help, I'd be happy to produce one.
__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/
More information about the Twisted-Python
mailing list