From 6a2e5a38d8f2a0b5fccd41180b586bac25d8ad24 Mon Sep 17 00:00:00 2001 From: George Su Date: Tue, 14 Jan 2020 19:49:11 -0800 Subject: [PATCH] Fix #105: Updated Sanic app to use multiple workers. --- server/src/app.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/server/src/app.py b/server/src/app.py index 4a607304c..ee227e258 100644 --- a/server/src/app.py +++ b/server/src/app.py @@ -8,6 +8,8 @@ from services.reporting import reports from configparser import ConfigParser from json import loads +from threading import Timer +from multiprocessing import cpu_count app = Sanic(__name__) @@ -105,7 +107,16 @@ async def biggestOffender(request): return await response.file(fileOutput) +def hello_world(): + print("Hello world.") + +@app.route('/test_timer') +async def test_timer(request): + Timer(20.0, hello_world) + return json("Done") + if __name__ == '__main__': configure_app() - app.run(host=app.config['Settings']['Server']['HOST'], port=app.config['Settings']['Server']['PORT'], debug=app.config['Settings']['Server']['DEBUG']) + app.run(host=app.config['Settings']['Server']['HOST'], port=int(app.config['Settings']['Server']['PORT']), + workers=cpu_count()//2, debug=app.config['Settings']['Server']['DEBUG'])