def run(self): """Sets up test server and loops over handling http requests.""" try: handler = get_server_handler() server_address = (self.address, self.port) httpd = StoppableWSGIServer(server_address, WSGIRequestHandler) #httpd = basehttp.WSGIServer(server_address, basehttp.WSGIRequestHandler) httpd.set_app(handler) self.started.set() except WSGIServerException, e: self.error = e self.started.set() return
def start_server(self, address='0.0.0.0', port=8000): handler = get_server_handler() def application(environ, start_response): environ['PATH_INFO'] = environ['SCRIPT_NAME'] + environ['PATH_INFO'] return handler(environ, start_response) from cherrypy.wsgiserver import CherryPyWSGIServer from threading import Thread self.httpd = CherryPyWSGIServer((address, port), application, server_name='django-test-http') self.httpd_thread = Thread(target=self.httpd.start) self.httpd_thread.start() #FIXME: This could be avoided by passing self to thread class starting django # and waiting for Event lock sleep(.5)