diff --git a/server/default_config.py b/server/default_config.py index 9033526..450ecb0 100644 --- a/server/default_config.py +++ b/server/default_config.py @@ -1,5 +1,10 @@ HOST = 'localhost' PORT = '8000' +WSGI_SERVER = 'wsgiref' +WSGI_SERVER_OPTIONS = {} +#WSGI_SERVER = 'gunicorn' +#WSGI_SERVER_OPTIONS = {'workers': 4, 'worker_class': 'eventlet'} + DEBUG = True DB_URI = 'sqlite:///techrec.db' AUDIO_OUTPUT = 'output/' diff --git a/server/server.py b/server/server.py index 903891e..798d63a 100644 --- a/server/server.py +++ b/server/server.py @@ -275,13 +275,58 @@ class RecServer: root='pages/')) +class DebugAPI(Bottle): + ''' + This application is useful for testing the webserver itself + ''' + def __init__(self): + Bottle.__init__(self) + self.route('/sleep/:milliseconds', callback=self.sleep) + self.route('/cpusleep/:howmuch', callback=self.cpusleep) + self.route('/big/:exponent', callback=self.big) + + def sleep(self, milliseconds): + import time + time.sleep(int(milliseconds)/1000.0) + return 'ok' + + def cpusleep(self, howmuch): + out = '' + for i in xrange(int(howmuch) * (10**3)): + if i % 11234 == 0: + out += 'a' + return out + + def big(self, exponent): + ''' + returns a 2**n -1 string + ''' + for i in xrange(int(exponent)): + yield str(i) * (2 ** i) + + def help(self): + response.content_type = 'text/plain' + return ''' + /sleep/ : sleep, than say "ok" + /cpusleep/ : busysleep, than say "ok" + /big/ : returns a 2**n -1 byte content + ''' + + def main_cmd(*args): """meant to be called from argparse""" c = RecServer() c._app.mount('/date', DateApp()) c._app.mount('/api', RecAPI()) - c._app.run(host=get_config()['HOST'], port=get_config()['PORT'], - debug=get_config()['DEBUG']) + if get_config()['DEBUG']: + c._app.mount('/debug', DebugAPI()) + + c._app.run(server=get_config()['WSGI_SERVER'], + host=get_config()['HOST'], + port=get_config()['PORT'], + debug=get_config()['DEBUG'], + **get_config()['WSGI_SERVER_OPTIONS'] + ) if __name__ == '__main__': from cli import common_pre