Last active
November 8, 2017 02:51
-
-
Save icve/8aeed0aab73c0bf56549792f0af3244d to your computer and use it in GitHub Desktop.
simple http server that responses OK
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
| 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