Permalink
Browse files

set cache-control to zero and fix high cpu load

  • Loading branch information...
1 parent ac96189 commit 1823c1954c991c8e7b1cc9d3a1766d0458a4aaa1 @posativ committed Oct 14, 2012
Showing with 14 additions and 9 deletions.
  1. +14 −9 acrylamid/lib/httpd.py
View
@@ -9,29 +9,30 @@
Launch a dumb webserver as thread."""
-from threading import Thread
import os
-import SimpleHTTPServer
-import SocketServer
-import posixpath
+import time
import urllib
+import posixpath
+from threading import Thread
+from SocketServer import TCPServer
+from SimpleHTTPServer import SimpleHTTPRequestHandler
-class ReuseAddressServer(SocketServer.TCPServer):
+
+class ReuseAddressServer(TCPServer):
"""avoids socket.error: [Errno 48] Address already in use"""
allow_reuse_address = True
def serve_forever(self):
"""Handle one request at a time until doomsday."""
while not self.kill_received:
- print self.wait
if not self.wait:
- print self.wait
self.handle_request()
+ else:
+ time.sleep(0.1)
-
-class AcrylServe(SimpleHTTPServer.SimpleHTTPRequestHandler):
+class AcrylServe(SimpleHTTPRequestHandler):
"""This is a modified version of python's -m SimpleHTTPServer to
serve on a specific sub directory of :func:`os.getcwd`."""
@@ -60,6 +61,10 @@ def translate_path(self, path):
path = os.path.join(path, word)
return path
+ def end_headers(self):
+ self.wfile.write('Cache-Control: max-age=0, must-revalidate\r\n')
+ SimpleHTTPRequestHandler.end_headers(self)
+
class Webserver(Thread):
"""A single-threaded webserver to serve while generation.

0 comments on commit 1823c19

Please sign in to comment.