0

edit: Ended up using the built-in render_template function to display output using Jinja2 markup, which proved to be a perfect solution.

1 Answer 1

2

Flask is a process and will keep running forever, unless it encounters a fatal exception.

Typically, a web server process exiting would be a terrible design.

Try this for the functionality you want: How to stop flask application without using ctrl-c

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for your input, John. However, I wasn't able to grasp how I could use this in the way I want it to work. What I'm trying to build is a frontend for multiple users, and I'm not sure how I would code the shutdown function into the application so that it'd kill the process after a user gets their scraped data. Sorry if I'm missing something. edit: Basically, I want it to scrape, print the data on browser and then stop. For multiple users.
Add in that shutdown_server function and call it from your process.
Added the following after the return statement, still no go. requests.post('http://localhost:5000/done') @app.route('/done', methods=['POST']) def done(): func = request.environ.get('werkzeug.server.shutdown') if func is None: raise RuntimeError('Not running with the Werkzeug Server') func()
Try installing werkzeug. pip install werkzeug
I have tried it with this snippet: codeshare.io/EgYKr It works, potential installation issue- which version flask are you running?
|

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.