Explanation of steps with terminal o/p
I have Macbook Pro (Catalina), 1 day I found the below issue while running the Django server (which runs on port 8000 by default):
python manage.py runserver 3000
(venv) Rishikeshs-MacBook-Pro:learn-django hygull$ python manage.py runserver 3000
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
July 27, 2021 - 23:54:05
Django version 3.2.3, using settings 'automated_classification.settings'
Starting development server at http://127.0.0.1:3000/
Quit the server with CONTROL-C.
Error: That port is already in use.
I tried to use the provided and executed but running only 1 of them was not solving my problem (I know there were some other answers too but somehow I solved my problem). E.g. I tried to rerun the above command but that too did not work (still the processes were active).
So I finally I used answer of @Cris with 1 more additional step as he & others have suggested. So my answer is just using their commands with Terminal output to make the executions more clearer to you.
lsof -P | grep ':3000' | awk '{print $2}'
(venv) Rishikeshs-MacBook-Pro:learn-django hygull$ lsof -P | grep ':3000' | awk '{print $2}'
36239
38272
Now I got the list of ids to kill, let's do.
kill -9 <PID>
(venv) Rishikeshs-MacBook-Pro:learn-django hygull$ kill -9 36239
(venv) Rishikeshs-MacBook-Pro:learn-django hygull$ kill -9 36239
-bash: kill: (36239) - No such process
(venv) Rishikeshs-MacBook-Pro:learn-django hygull$ kill -9 38272
(venv) Rishikeshs-MacBook-Pro:learn-django hygull$ kill -9 38272
-bash: kill: (38272) - No such process
And now, let's try to rerun the command.
python manage.py runserver 3000
(venv) Rishikeshs-MacBook-Pro:learn-django hygull$ python manage.py runserver 3000
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
July 27, 2021 - 23:55:53
Django version 3.2.3, using settings 'project.settings'
Starting development server at http://127.0.0.1:3000/
Quit the server with CONTROL-C.
FINAL
kill -9 $(lsof -P | grep ':3000' | awk '{print $2}')
You can combine the above 2 steps in 1 line & execute to kill process listening on port 3000.