简体   繁体   中英

How to gracefully shutdown python SimpleHTTPServer in ubuntu?

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 (or ) the server. (或服务器。 But as I am a newbie I am not able to actually do it.

In the 3 rd link above. 在上述第3连结。 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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM