开发者

How to get Intellij-idea close Flask dev server properly?

I use IDEA 10.5 for my Flask experimentation. Flask has en embedded test server (like Django does)

When I launch my test class, the dev server launches as well on port开发者_Python百科 5000. All good. * Running on http://127.0.0.1:5000/

When I click on the "Stop process" button (red square), I get the message saying the process is finished : Process finished with exit code 143

However the server is still alive (responds to requests) and I can see I still have a python process running.

Obviously this prevents me from relaunching the test straight away, I have to kill the server process first.

How do you manage to get both your program and the server ending at the same time ?


I guess what happens is that you start your flask app which then is forking the development server as a new process. If you stop the app the forked process is still running.

This looks like a problem, that cannot easily be solved within the means of your IDE. You could add something to your main to kill the already running server process, before starting the app again, but that seems ugly.

But why don't you just start your app with app.run(debug=True) as described in flask doc? The server will reload automatically everytime you changed your app so you don't have to stop and restart it manually.

EDIT: Something a bit quirky just came to my mind: if you just need a comfortable way to kill the server from within the IDE all you have to do is to introduce a syntactical error in one of the places the reloader monitors, save the file and the server will choke on it and die :)


This doesn't happen anymore with newer versions (tested with PyCharm 2.0)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜