1

I'm new to Python. As a part of a project I'm trying to deploy a Flask server locally, through the Windows command line.

My Python version is 3.6.0.

The code:

from flask import Flask

app = Flask(__name__)

@app.route('/') def index():
    return '<h1>Hello World!</h1>'

if __name__ == "__main__":
    app.run()

The problem:

It's about killing the script as it runs. Launching this script with python deploy.py and hitting CTRL+C shuts it off.

BUT - if I hit access that '/' route via the browser once or more, and a moment later try to kill the script in the same manner, then it would take about 10 seconds of nothing until it responds and is finally killed.

Why is this happening? How can I shut the server off immediately each time for continuous and quick development?

Thanks!!

1 Answer 1

1

Well if your goal is continuous and quick development, then you can change flask's configuration.

Best solution for your problem would be setting the DEBUG setting to True. If DEBUG is set to True, then flask will automatically reload the server on code changes.

There are a few ways to do this but the easiest one(because you said you are a beginner) is to pass the debug argument to app.run()

from flask import Flask

app = Flask(__name__)

@app.route('/') 
def index():
    return '<h1>Hello World!</h1>'

if __name__ == "__main__":
    app.run(debug=True)
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, your suggestion was helpful + it also led me to the understanding that Flask is not just a HTTP server library as I thought, but rather a micro-framework with more features than that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.