重新启动Django服务器会出现以下错误:
this port is already running....
这个问题只发生在Ubuntu上,而不是其他操作系统上。如何释放端口以重新启动服务器?
重新启动Django服务器会出现以下错误:
this port is already running....
这个问题只发生在Ubuntu上,而不是其他操作系统上。如何释放端口以重新启动服务器?
当前回答
>> ps aux | grep manage
ubuntu 3438 127.0.0 2.3 40256 14064 pts/0 T 06:47 0:00 python manage.py runserver
>> kill -9 3438
其他回答
一个更简单的解决方案是键入sudo fuser -k 8000/tcp。 这将杀死与端口8000关联的所有进程。
编辑:
对于osx用户,可以使用sudo lsof -t -i tcp:8000 | xargs kill -9
在终端输入ps aux | grep runserver 回车 在结果中使用PID执行kill -9 <PID>
对于实例,如果步骤1的结果如下所示
root 1041 0.0 0.1 266912 34580 pts/3 S+ 11:31 0:01 python3 manage.py runserver 0.0.0.0:3030
root 1696 4.5 0.1 126128 40708 ? S Feb14 925:43 /usr/local/bin/python manage.py runserver 0.0.0.0:8000
1041和1696是pid。我们需要在这些进程中选择我们想要终止的进程。
netstat -ntlp
它会像这样。
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 6599/python
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN -
tcp 0 0 192.168.124.1:53 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN -
tcp6 0 0 :::3306 :::* LISTEN
所以现在只要关闭Django/python已经运行的端口,杀死与之相关的进程。
kill -9 PID
对我来说
kill -9 6599
现在运行Django应用程序。
如果你在MAC中遇到这个问题,你只需要打开活动监视器并强制相当python,然后再试一次
不要使用CTRL + Z来停止服务器,使用CTRL + C来停止服务器,我在我的linux (fedora)中也有同样的问题,我曾经使用CTRL + Z停止服务器,再次使用sudo fuser -k 8000/tcp命令杀死服务器,这工作得很好。但后来当我开始使用CTRL + C时,我不再遇到端口运行的问题。