Skip to content

Instantly share code, notes, and snippets.

@astrofrog
Created February 5, 2014 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astrofrog/8832745 to your computer and use it in GitHub Desktop.
Save astrofrog/8832745 to your computer and use it in GitHub Desktop.
import BaseHTTPServer
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)
while True:
try:
httpd.handle_request()
return
except:
pass
run_while_true()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment