2

I found here answers how to stop the Django Server on Linux but not on windows.

Do I really need to restart my machine ?

user3541631
  • 3,686
  • 8
  • 48
  • 115
  • Where you run your server? cmd or powershell? Is it says "The port already in use." – shafik Apr 03 '19 at 14:12
  • no, I'm run it from Pycharm terminal, so I presume cmd; If I close a project in Pycharm and forget to close the server, it remains open; if I start again a project the initial server is seen, and now way to close it; to use a different server – user3541631 Apr 03 '19 at 14:55
  • If you try to re run the project then what will see? – shafik Apr 03 '19 at 14:56
  • the initial server, if I make change in code nothing happens – user3541631 Apr 03 '19 at 14:57
  • Try to kill the port the server already run then run the server again. https://stackoverflow.com/questions/39632667/how-to-kill-the-process-currently-using-a-port-on-localhost-in-windows/55218770#55218770 – shafik Apr 03 '19 at 15:02

5 Answers5

8

In your terminal, spam ctrl+c a few times.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
3
  • Open Resource Monitor in the Command Prompt using the command resmon.

  • At the "Listening Ports", find the port you're using. See Resource Monitor here.

  • In my case, is Port 8000.

  • Get the PID, in this example is 20132.

  • Open Task Manager, go to Tab Details, find the PID and end the task.

See Task Manager here

General Grievance
  • 4,555
  • 31
  • 31
  • 45
angelacpd
  • 564
  • 6
  • 9
1

For those looking for a programmatic solution, closing port 8000 and all associated connections (there may be more than one) can be done with a .bat script:

@ECHO OFF
SET /A port=8000
FOR /F "tokens=5" %%T IN ('netstat -ano ^| findstr :%port%') DO (
    SET /A processid=%%T
    TASKKILL /PID %%T /F
)

Note that the CMD line netstat -ano ^| findstr :%port% is used to list the connections using port 8000:

  >netstat -ano | findstr :8000
  TCP    0.0.0.0:8000           0.0.0.0:0              LISTENING       10920
  TCP    10.0.1.11:8000         10.0.1.11:14813        ESTABLISHED     10920
  TCP    10.0.1.11:8000         10.0.1.11:14814        ESTABLISHED     10920
  TCP    10.0.1.11:8000         10.0.1.11:14815        ESTABLISHED     10920
  TCP    10.0.1.11:14813        10.0.1.11:8000         ESTABLISHED     2628
  TCP    10.0.1.11:14814        10.0.1.11:8000         ESTABLISHED     2628
  TCP    10.0.1.11:14815        10.0.1.11:8000         ESTABLISHED     2628```
Alfred Wallace
  • 1,741
  • 1
  • 14
  • 32
0

Edit1: On windows I used 'Run manage.py Task' in pycharm and I simply closed pycharm and the port is not in use anymore

Edit2: If you are using 'Run manage.py Task' in pycharm, check this: My picture of terminating server There's a in-built option for stopping the server in pycharm

SaeedR80
  • 1
  • 1
0

Just Press ctr+C instead of CTRL+BREAK (There is no BREAK key present on keyboard) . To fix unapplied migration I wanted to quit server