Serob_b
Serob_b

Reputation: 1059

Django check if server is already running

I am on Windows, and run my Django server via manage.py runserver 8001. When I have already running server and enter the mentioned command again, it starts another server listening the same (8001) port. What I would like to do is to determine if server is already running and stop the execution of the command, or stop the running server and then run the new server.

UPDATE: I need to do the described things automatically. Throwing an error is also OK. But why runserver command is not throwing an error, if the port is already busy?? That's a standard behavior of platforms that I have experience with (Java Tomcat server, PHP) and also on Ubuntu with Django, as this question clarifies.

Upvotes: 1

Views: 9797

Answers (2)

Mugoya Dihfahsih
Mugoya Dihfahsih

Reputation: 425

Probably you are running two Django projects at the same time either you are running one project using command prompt and a second project using the IDE terminal

Solution

Terminate these two projects running using CTR + C or check the project that's using the port 8001 by doing this

on your command prompt

netstat -ano | findStr "8001"

You can also check which process on you machine is being run on which port by doing the following on terminal:

netstat -a -b -o -n

**-a **Displays all connections and listening ports.

-b Displays the executable involved in creating each connection or listening port.

-n Displays addresses and port numbers .

-o Displays the owning process ID.

Upvotes: 1

hrmnjt
hrmnjt

Reputation: 193

You can do that in using cmd:

 netstat -ano | findStr "8001"

Upvotes: 2

Related Questions