Python/Flask: Application is running after closing

♀尐吖头ヾ 提交于 2021-02-19 08:06:06

问题


I'm working on a simple Flask web application. I use Eclipse/Pydev. When I'm working on the app, I have to restart this app very often because of code changes. And that's the problem. When I run the app, I can see the frame on my localhost, which is good. But when I want to close this app, just click on the red square which should stop applications in Eclipse, sometimes (often), the old version of application keeps running so I can't test the new version. In this case the only thing which helps is to force close every process in Windows Task Manager.

Will you give me any advice how to manage this problem? Thank you in advance.

EDIT: This maybe helps: Many times, I have to run the app twice. Otherwise I can't connect.


回答1:


This actually shouldn't happen with the latest versions of PyDev (i.e.: since PyDev 3.4.1: http://pydev.org/history_pydev.html, PyDev should kill all the subprocesses of the main process).

So, can you check which PyDev version are you using?

If you're in the latest version of PyDev, you can use Ctrl+Shift+F9 to terminate/relaunch by default.

But as you're dealing with flask, you should be able to use it to reload automatically on code-changes without doing anything by setting use_reloader=True.

I.e.: I haven't actually tested, but its documentation says that you can set the reload flag for that run(use_reloader=True) -- and PyDev should even be able to debug it (I'll take a better look and improve the PyDev docs on that area later on).




回答2:


I've faced the same problem and solved it. I think it may help.

When we run a flask based site locally it is assigned to a TCP port: 5000 and the Default IP: 127.0.0.1:5000

Sometimes TCP connection remains even after closing the program or terminating the code. So, The idea is kill the TCP connection. You can do it from command-prompt(cmd)

Two Steps to Follow:
1. See the Process ID(PID) for the running TCP connection.
Go to cmd and type:

netstat -ano

  1. Kill The Process By PID. Command for this: taskkill /f /im [PID]. Example is showed bellow.

    taskkill /f /im 7332




回答3:


I've had a very similar thing happen to me. I was using CherryPy rather than Flask, but my solution might still work for you. Oftentimes browsers save webpages locally so that they don't have to re-download them every time the website is visited. This is called caching, and although it's very useful for the average web user, it can be a real pain to app developers. If you're frequently generating new versions of the application, it's possible that your browser is displaying an old version of the app that it has cached instead of the most up to date version. I recommend clearing that cache every time you restart your application, or disabling the cache altogether.



来源:https://stackoverflow.com/questions/24349335/python-flask-application-is-running-after-closing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!