From 33f712ef9b56954b4a5185c82dcd659ac8bf820c Mon Sep 17 00:00:00 2001 From: Channel Cat Date: Fri, 14 Oct 2016 03:42:20 -0700 Subject: [PATCH] Proper errors when server cannot bind --- sanic/server.py | 9 ++++++++- tests/performance/sanic/simple_server.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index 420a681b..f824d17e 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -151,7 +151,14 @@ def serve(host, port, request_handler, after_start=None, before_stop=None, debug request_timeout=request_timeout, request_max_size=request_max_size, ), host, port) - http_server = loop.run_until_complete(server_coroutine) + try: + http_server = loop.run_until_complete(server_coroutine) + except OSError as e: + log.error("Unable to start server: {}".format(e)) + return + except: + log.exception("Unable to start server") + return # Run the on_start function if provided if after_start: diff --git a/tests/performance/sanic/simple_server.py b/tests/performance/sanic/simple_server.py index 41a58c3d..443402db 100644 --- a/tests/performance/sanic/simple_server.py +++ b/tests/performance/sanic/simple_server.py @@ -18,4 +18,4 @@ async def test(request): async def test(request): return json({ "test": True, "files": request.files, "fields": request.form }) -app.run(host="0.0.0.0", port=sys.argv[1], debug=True) \ No newline at end of file +app.run(host="0.0.0.0", port=sys.argv[1]) \ No newline at end of file