Often, when restarting Django runserver, if I use the same port number, I get a \'port is already in use\' message. Subsequently, I need to increment the port number each t
I use pkill -If 'manage.py'
(-I
means interactive, -f
matches more than just the process name). See How to kill all processes with a given partial name? for more info on pkill.
You do not want to simply increment the port number when restarting a Django server. This will result in having multiple instances of the Django server running simultaneously. A better solution is to kill the current instance and start a new instance.
To do this, you have multiple options. The easiest is
Python2: $ killall -9 python
Python3: $ killall -9 python3
If for some reason, this doesn't work, you can do
$ kill <pid>
where <pid>
is the process id found from a simple $ ps aux | grep python
command.
No, he's not an idiot guys. Same thing happens to me. Apparently it's a bug with the python UUID process with continues running long after the django server is shutdown which ties the port up.
You must have been doing control + z .. Instead do control + c that will kill the server session... Cheers!!!
netstat -ntlp
See my complete answer here. https://stackoverflow.com/a/34824239/5215825
You're getting that message because the server is already running (possibly in the background). Make sure to kill the process (bring it to the foreground and press ctrl-c) to stop the process.