django development server, how to stop it when it run in background?

PythonDjangoServer

Python Problem Overview


I use a Cloud server to test my django small project, I type in manage.py runserver and then I log out my cloud server, I can visit my site normally, but when I reload my cloud server, I don't know how to stop the development server, I had to kill the process to stop it, is there anyway to stop the development?

Python Solutions


Solution 1 - Python

The answer is findable via Google -- and answered in other forums. Example solution is available on the Unix & Linux StackExchange site.

To be explicit, you could do:

ps auxw | grep runserver

This will return the process and its respective PID, such as:

de        7956  1.8  0.6 540204 55212 ?        Sl   13:27   0:09 /home/de/Development/sampleproject/bin/python ./manage.py runserver

In this particular case, the PID is 7956. Now just run this to stop it:

kill 7956

And to be clear / address some of the comments, you have to do it this way because you're running the development server in the background (the & in your command). That's why there is no "built-in" Django stop option...

Solution 2 - Python

One liner..

pkill -f runserver

Solution 3 - Python

well it seems that it's a bug that django hadn't provided a command to stop the development server . I thought it have one before~~~~~

Solution 4 - Python

Try this

lsof -t -i tcp:8000 | xargs kill -9

Solution 5 - Python

Ctrl+c should work. If it doesn't Ctrl+/ will force kill the process.

Solution 6 - Python

As far as i know ctrl+c or kill process is only ways to do that on remote machine. If you will use Gunicorn server or somethink similar you will be able to do that using Supervisor.

Solution 7 - Python

We can use the following command.

> -> netstat -ntlp

then we will get number of process running with PID, find our python server PID and Kill process.

> -> kill -9 PID

For example:
enter image description here

Solution 8 - Python

From task manager you can end the python tasks that are running. Now run python manage.py runserver from your project directory and it will work.

Solution 9 - Python

Programmatically using a .bat script in Command Prompt in Windows:

@ECHO OFF
SET /A port=8000
FOR /F "tokens=5" %%T IN ('netstat -ano ^| findstr :%port%') DO (
    SET /A processid=%%T
    TASKKILL /PID %%T /F
)

gives

SUCCESS: The process with PID 5104 has been terminated.

Solution 10 - Python

You can Quit the server by hitting CTRL-BREAK.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbricksView Question on Stackoverflow
Solution 1 - PythonuserView Answer on Stackoverflow
Solution 2 - Pythonarchit guptaView Answer on Stackoverflow
Solution 3 - PythonbricksView Answer on Stackoverflow
Solution 4 - PythonPeter WauyoView Answer on Stackoverflow
Solution 5 - PythontimotaohView Answer on Stackoverflow
Solution 6 - PythonwolendranhView Answer on Stackoverflow
Solution 7 - PythonWillie ChengView Answer on Stackoverflow
Solution 8 - PythonRamandeep SinghView Answer on Stackoverflow
Solution 9 - PythonAlfred WallaceView Answer on Stackoverflow
Solution 10 - PythonMaheshView Answer on Stackoverflow