1

I am trying to create a web application using flask. I have already gotten somewhat comfortable with using python, and have done so using spyder, inside of Anacanda Navigator. Now I am playing around with flask doing basic functions and have successful so far by testing it out in local server 127.0.0.1:5000. The problem I am having is that I cannot stop the server once I run the script in spyder. I have stopped the script and run other scripts through the console, but the local server remains the same.

The reason this is a problem for me is because when I try to change files and run a different flask script, the server does not update with the new information. For example, if I run a flask script that returns "Hello World" on the main page, and then I stop that file, open a new file that has a different flask script that returns "The sky is blue" the server does not change when I check it on chrome or any other browser. It will onyl return "Hello World"

I have been able to fix this problem by completely restarting my computer, but I am wondering if there is another way, just to restart the local server, 127.0.0.1:5000. Thank You!

Also I am using windows

3 Answers3

2

I do : "Run > Configuration per file > Execute in an external system terminal", then when you run your .py containing the app.run, it will be launched in an external console. If you close the console the server will be closed too.

mathieu.letombe
  • 343
  • 1
  • 6
0

To Kill the local server, you may use Ctrl+C command and not any other command. This command is also mentioned when the server is up and running.

abhishek kumar
  • 339
  • 3
  • 11
0

I've been having this precise issue and have been smashing my head against the wall for a couple of hours. I posted the referenced StackOverflow question (my first actually) and it seems that running a script from inside Spyder is the wrong way to go as it leaves runaway background processes running, even after restarting Spyder.

I got the recommendation to only launch my *.py code from the command prompt. Furthermore I was told to do this:

set FLASK_APP=main1.py then set FLASK_DEBUG=1 then flask run

though I'm not sure what that does, so I will investigate. I was about to restart my computer as a last ditch effort until I looked in my Windows Task Manager and found some Python tasks running. After [end task] them both I was able to launch the updated webpage on my local host.

Peej1226
  • 132
  • 12