edit: Ended up using the built-in render_template function to display output using Jinja2 markup, which proved to be a perfect solution.
Asked
Active
Viewed 569 times
1 Answers
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
-
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.** – leet Jun 05 '15 at 18:24
-
Add in that shutdown_server function and call it from your process. – John Jun 05 '15 at 18:29
-
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()` – leet Jun 05 '15 at 18:53
-
Try installing werkzeug. pip install werkzeug – John Jun 05 '15 at 19:15
-
I have tried it with this snippet: http://codeshare.io/EgYKr It works, potential installation issue- which version flask are you running? – John Jun 05 '15 at 19:21
-
That snippet works for me too but when I integrate it into my script, it doesn't work. On the console it keeps scraping the same pages over and over again, and on the browser it just hangs on loading. I don't see the output on the browser nor does the script stop. I wonder if there is a problem in my scraper code. – leet Jun 05 '15 at 19:38
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/79811/discussion-between-john-and-leet). – John Jun 05 '15 at 19:58