WSGI_SERVER selectable + DebugAPI
This commit is contained in:
parent
ddeef6ab78
commit
be56c206b4
2 changed files with 52 additions and 2 deletions
|
@ -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/'
|
||||
|
|
|
@ -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/<int:milliseconds> : sleep, than say "ok"
|
||||
/cpusleep/<int:howmuch> : busysleep, than say "ok"
|
||||
/big/<int:exponent> : 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
|
||||
|
|
Loading…
Reference in a new issue