How to 'clear' the port when restarting django runserver

前端 未结 19 2127
盖世英雄少女心
盖世英雄少女心 2020-12-12 11:23

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

相关标签:
19条回答
  • 2020-12-12 11:54

    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.

    0 讨论(0)
  • 2020-12-12 11:55

    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.

    0 讨论(0)
  • 2020-12-12 11:56

    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.

    0 讨论(0)
  • 2020-12-12 11:56

    You must have been doing control + z .. Instead do control + c that will kill the server session... Cheers!!!

    0 讨论(0)
  • 2020-12-12 11:57
    netstat -ntlp
    

    See my complete answer here. https://stackoverflow.com/a/34824239/5215825

    0 讨论(0)
  • 2020-12-12 12:02

    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.

    0 讨论(0)
提交回复
热议问题