Created
September 1, 2014 10:45
-
-
Save jorge-lavin/8d29527265f7395717a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import BaseHTTPServer | |
def keep_running(): | |
user_keystroke = raw_input() | |
if user_keystroke == 'q': | |
return False | |
else: | |
return True | |
def run_while_true(server_class=BaseHTTPServer.HTTPServer, | |
handler_class=BaseHTTPServer.BaseHTTPRequestHandler): | |
""" | |
This assumes that keep_running() is a function of no arguments which | |
is tested initially and after each request. If its return value | |
is true, the server continues. | |
""" | |
server_address = ('', 8000) | |
httpd = server_class(server_address, handler_class) | |
print('Serving at port 8000, press q and ENTER to stop server') | |
while keep_running(): | |
httpd.handle_request() | |
if __name__ == '__main__': | |
run_while_true() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment