Rune Halvorsen committed 0f5af5c

Cleaned up the timeout/watchdog

Comments (0)

Files changed (1)

 import re
 import os.path
 import uuid
-import thread
-import threading
 import sys
+import time
 from  optparse import OptionParser
 from wsgiref.simple_server import make_server, WSGIRequestHandler
     return app
 def run_test_server(app, options):
-    watchdog = None
-    if options.timeout:
-        watchdog = threading.Timer(options.timeout, thread.interrupt_main)
-        watchdog.daemon = True
-        watchdog.start()
         # we don't use werkzeugs wsgi server because it handles
         # keyboardinterrupt on its own. We want to do so ourselves.
         httpd = make_server('', 8080, app, handler_class=SilentWSGIRequestHandler)
+        httpd.timeout = 0.5
         print >> sys.stderr, "Serving"
-        httpd.serve_forever()
+        starttime = time.time()
+        while True:
+            httpd.handle_request()
+            if options.timeout and time.time() - starttime > options.timeout:
+                break
     except KeyboardInterrupt:
-        # should differentiate between watchdog kill and normal keyboardinerrupt
-        if watchdog and not watchdog.finished:
-            watchdog.cancel()
+        pass
     print >> sys.stderr, "Finished"
     parser.add_option("-w", "--watchdog", dest="timeout",
                       default=None, action="store", type="float",
-                      help="How long to run the server before forcefully killing it. By default it runs until tests finish. If a bug causes that to not happen, it runs forever.")
+                      help="How long to run the server before forcefully killing it.")
     return parser