From 1bf7e2f1b0636c9a1a1af147f3c130f9734b1bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=2E=20K=C3=A4rkk=C3=A4inen?= Date: Tue, 31 Mar 2020 13:03:19 +0300 Subject: [PATCH] Allow autoreloader with multiple workers and run it earlier. --- sanic/app.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/sanic/app.py b/sanic/app.py index c38f4f7c..d228e292 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -1117,6 +1117,15 @@ class Sanic: # Allow for overriding either of the defaults auto_reload = kwargs.get("auto_reload", auto_reload) + if auto_reload: + if os.name != "posix": + # This condition must be removed after implementing + # auto reloader for other operating systems. + raise NotImplementedError + + if os.environ.get("SANIC_SERVER_RUNNING") != "true": + return reloader_helpers.watchdog(2) + if sock is None: host, port = host or "127.0.0.1", port or 8000 @@ -1158,18 +1167,7 @@ class Sanic: ) workers = 1 if workers == 1: - if auto_reload and os.name != "posix": - # This condition must be removed after implementing - # auto reloader for other operating systems. - raise NotImplementedError - - if ( - auto_reload - and os.environ.get("SANIC_SERVER_RUNNING") != "true" - ): - reloader_helpers.watchdog(2) - else: - serve(**server_settings) + serve(**server_settings) else: serve_multiple(server_settings, workers) except BaseException: