0

I started the server using python -m SimpleHTTPServer

I am a complete beginner to web development and was using Python SimpleHTTPServer 2.7 in ubuntu. While trying to shutdown the server, ctl + c gives me a traceback complaining about being interrupted.

After looking at threads:
1. How do I shut down a python simpleHTTPserver?
2. Shutdown socketserver serve_forever() in one-thread Python application
3. Shutting down an HTTPServer

I can understand that it is possible to properly (or gracefully) shutdown the server. But as I am a newbie I am not able to actually do it.

P.S.: In the 3rd link above. There is also a code to "I think gracefully shutdown the SimpleHTTPServer". But I am also not able to understand - how to run that code?

Please Help
Thank You in advance

  • What's exactly the problem with interrupting it through Ctrl-C? It's the regular way to interrupt it, it's not like something gets ruined... – Matteo Italia Mar 12 '18 at 20:55

2 Answers2

0

A graceful shutdown is just ending the socket session before you shutdown the server. Basically if you add a try catch to the code that handles the keyboard exception, then under that run a socket shutdown, then you're golden. But add code so we can help better. edit - spelling and grammar

  • I started the server using python -m SimpleHTTPServer – Anurag Bansal Mar 23 '18 at 11:09
  • Now, if I do not do anything and just want to shut down the server including all background processes (if any). Then what shall I do because ctrl + c gives a traceback which spooks me, that some data loss might have occured. – Anurag Bansal Mar 23 '18 at 11:12
0

If you have started server like

python -m SimpleHTTPServer 8888 

Then ctr+c will take server down but if you have stared server like

python -m SimpleHTTPServer 8888 &

then you will have to kill the process using command

ps 

then you will get running processes like

PID TTY          TIME CMD
7247 pts/3     00:00:00 python
7360 pts/3     00:00:00 ps
23606 pts/3    00:00:00 bash

so just go for kill:

kill -9 7247
py-D
  • 661
  • 5
  • 8
  • Thank You for the reply .... ctrl + c gives a traceback which spooks me, that some data loss might have occured ... might be a difference between linux and windows (as I am using ubuntu). Please correct me if I am wrong – Anurag Bansal Mar 23 '18 at 11:13