Python django 开发服务器,后台运行时如何停止

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27066366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 01:24:05  来源:igfitidea点击:

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

pythondjangoserver

提问by bricks

I use a clode server to test my django small project , I type in manage.py runserver & ,and then I log out my cloude server ,I can visit mysite normally but when I reload my cloude 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?

我使用clode服务器来测试我的django小项目,我输入manage.py runserver &,然后我注销我的cloude服务器,我可以正常访问mysite但是当我重新加载我的cloude服务器时,我不知道如何停止开发服务器,我不得不杀死进程来停止它,无论如何要停止开发?

采纳答案by user

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

答案可以通过谷歌找到——并在其他论坛中得到解答。Unix & Linux StackExchange 站点上提供了示例解决方案。

To be explicit, you could do:

明确地说,你可以这样做:

ps auxw | grep runserver

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

这将返回进程及其各自的 PID,例如:

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:

在这种特殊情况下,PID 是7956。现在只需运行它来停止它:

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...

为了清楚/解决一些评论,您必须这样做,因为您在后台运行开发服务器(&在您的命令中)。这就是为什么没有“内置”的 Django 停止选项......

回答by wolendranh

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.

据我所知 ctrl+c 或 kill process 只是在远程机器上执行此操作的方法。如果您将使用 Gunicorn 服务器或类似的东西,您将能够使用 Supervisor 做到这一点。

回答by bricks

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~~~~~

好吧,这似乎是 django 没有提供停止开发服务器的命令的错误。之前还以为有呢~~~~~

回答by Ramandeep Singh

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

从任务管理器中,您可以结束正在运行的 Python 任务。现在python manage.py runserver从您的项目目录运行,它将工作。

回答by archit gupta

One liner..

一个班轮..

pkill -f runserver

回答by Mahesh

You can Quit the server by hitting CTRL-BREAK.

您可以通过按CTRL-BREAK退出服务器。

回答by Willie Cheng

We can use the following command.

我们可以使用以下命令。

-> netstat -ntlp

-> netstat -ntlp

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

然后我们将获得使用PID运行的进程数,找到我们的python服务器PID和Kill进程。

-> kill -9 PID

-> 杀死 -9 PID

For example:
enter image description here

例如:
在此处输入图片说明