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
So now just close the port in which Django/python running already by killing the process associated with it.
kill -9 PID
in my case
kill -9 6599
Now run your Django app.
回答 2
ps aux | grep -i manage
after that you will see all process
ubuntu@ip-10-154-22-113:~/django-apps/projectname$ ps aux | grep -i manage
ubuntu 34390.02.34022814064 pts/0 T 06:470:00 python manage.py runserver project name
ubuntu 34401.49.720099659324 pts/0Tl06:472:52/usr/bin/python manage.py runserver project name
ubuntu 45810.00.17988892 pts/0 S+10:020:00 grep --color=auto -i manage
kill -9 process id
e.d kill -93440`enter code here`after that :
python manage.py runserver project name
This is an expansion on Mounir’s answer. I’ve added a bash script that covers this for you. Just run ./scripts/runserver.sh instead of ./manage.py runserver and it’ll work exactly the same way.
#!/bin/bash
pid=$(ps aux | grep "./manage.py runserver" | grep -v grep | head -1 | xargs | cut -f2 -d" ")
if [[ -n "$pid" ]]; then
kill $pid
fi
fuser -k 8000/tcp
./manage.py runserver
For me, this happens because my API request in Postman is being intercepted by a debugger breakpoint in my app… leaving the request hanging. If I cancel the request in Postman before killing my app’s server, the error does not happen in the first place.
–> So try cancelling any open requests you are making in other programs.
On macOS, I have been using sudo lsof -t -i tcp:8000 | xargs kill -9 when I forget to cancel the open http request in order to solve error = That port is already in use. This also, complete closes my Postman app, which is why my first solution is better.
It seems that IDEs, VSCode, Puppeteer, nodemon, express, etc. causes this problem, you ran a process in the background or just closed the debugging area [browser, terminal, etc. ] or whatever , anyway, i have answered same question before,
Here you are it’s link
In case You are using the VSC’s screen terminal, The error might be due to the fact that you already runserver in some other shell.
Just click on the dropbox on the left of the + sign in the header of the terminal of VSC and select some other shell and check if the server is already running there. Quit that server and you are ready to launch a another server.