Skip to content

Instantly share code, notes, and snippets.

@icve
Last active November 8, 2017 02:51
Show Gist options
  • Select an option

  • Save icve/8aeed0aab73c0bf56549792f0af3244d to your computer and use it in GitHub Desktop.

Select an option

Save icve/8aeed0aab73c0bf56549792f0af3244d to your computer and use it in GitHub Desktop.
simple http server that responses OK
from http.server import BaseHTTPRequestHandler, HTTPServer
from time import sleep
PORT = 8008
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
''' method that gets call when GET is recived'''
print(self.path)
self.send_response(200)
self.end_headers()
self.wfile.write("OK".encode())
httpd = HTTPServer(("0.0.0.0", PORT), Handler)
# don't block
httpd.timeout = 0
print("serving at port", PORT)
try:
while True:
#insert other code here
sleep(1)
#handle one req, without blocking
httpd.handle_request()
except KeyboardInterrupt as e:
# clean up before exit
httpd.server_close()
print("")
print("closed")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment