2

When I run the Django runserver command it shows port is already in use. So every time I need to kill the process that uses the port and run the server again.

Can anyone give me a permanent solution to this?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
pratik jaiswal
  • 1,855
  • 9
  • 27
  • 59
  • Of course you need to kill the old server before starting it again; only one process can bind to any given port at once. Are you running `manage.py runserver` multiple times? If so, why? – ChrisGPT was on strike Sep 03 '17 at 15:46

4 Answers4

3

You can use another port, coz may be the port you are using have some problem.

python manage.py runserver 8080

and yes, you need to kill the previous running server.

Astik Anand
  • 12,757
  • 9
  • 41
  • 51
1

If you have other processes running you should always kill them before trying to run another process on the same port.

I use the following Terminal command:

sudo fuser -k 8000/tcp

This will kill the process on the specified port.

You can also run the Django development server on other ports assuming they are not already in use by another programme.

python manage.py runserver 8001
drew
  • 771
  • 1
  • 4
  • 11
1

This occurs when you use CTRL+Z instead of CTRL+C.

CTRL+Z ->  Suspend process
CTRL+C ->  Stop process

There are many recommendations around StackOverflow. I would like to recommend the best way from my perspective(You simply need to remember two commands).

Firstly see the jobs in the background by simply typing jobs in the terminal.

This is what shows up after you type job

You can see the job number as 4, 5, and 6. So If I want to kill the process for job 6 which is python manage.py runserver. I simply can type kill %6

Killing job no 6

Though sometimes CTRL+C doesn't kill the process. And if above doesn't work well you can use this command:

sudo fuser -k 8000/tcp
0

Just run this command

sudo lsof -t -i tcp:8000 | xargs kill -9    

if you face any other issue , click this link https://stackoverflow.com/a/70213044/17497683

Syed
  • 1
  • 5