2

I am writing a very simplistic application in Python3 which simply runs certain server-side commands from POST input received via the Python http.server.BaseHTTPRequestHandler, HTTPServer modules.

Currently, my code is as follows:

mysql_tools.f_print("Starting HTTP server on %s:%s.." % SERVER_ADDRESS)
httpd = HTTPServer(SERVER_ADDRESS, S)
mysql_tools.f_print("Server started. Now serving port %s." % SERVER_ADDRESS[1])
httpd.serve_forever()

Where S is the BaseHTTPRequestHandler class.

Now, I want to be able to have console input also. The application runs in a CMD window and simply displays "Server started. Now serving port 1010", however I want to be able to type, for example, "stop" into the CMD window and process accordingly, or "restart" or "forcerequest" etc etc. But as you may know, it does not have any input because of the "serve_forever()", it disregards any future lines of code as it appears to loop indefinitely.

Any advice or alternate ways to serve the port would be appriciateted.

1 Answer 1

1

AFAIK, there's no way, at least not from that window, (it's not due to serve_forever), any server will behave that way, it just listens for a SIGTERM (CTRL+C or shutdown()).

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I'll have to use a different message to send debug commands, probably just from pushing it through via POST.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.