Convert Flask.run into a noop when run from the CLI

This commit is contained in:
Armin Ronacher 2017-01-29 12:26:52 +01:00
parent 42fbbb4cbb
commit c9b33d0e86
4 changed files with 30 additions and 0 deletions

View file

@ -412,6 +412,13 @@ def run_command(info, host, port, reload, debugger, eager_loading,
"""
from werkzeug.serving import run_simple
# Set a global flag that indicates that we were invoked from the
# command line interface provided server command. This is detected
# by Flask.run to make the call into a no-op. This is necessary to
# avoid ugly errors when the script that is loaded here also attempts
# to start a server.
os.environ['FLASK_RUN_FROM_CLI_SERVER'] = '1'
debug = get_debug_flag()
if reload is None:
reload = bool(debug)