pratik jaiswal
pratik jaiswal

Reputation: 2065

Django says port is already in use

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?

Upvotes: 2

Views: 7646

Answers (5)

Hama
Hama

Reputation: 1

more than one Terminal may be opened and running at the same time

Upvotes: 0

Syed
Syed

Reputation: 1

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

Upvotes: 0

Pramod Pujara
Pramod Pujara

Reputation: 23

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

Upvotes: 1

drew
drew

Reputation: 781

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

Upvotes: 1

Astik Anand
Astik Anand

Reputation: 13047

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.

Upvotes: 3

Related Questions