Last active
September 16, 2015 18:38
-
-
Save brettvitaz/240e190accec3a00e9d1 to your computer and use it in GitHub Desktop.
Start a temporary HTTP to serve a quick file and bail.
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 signal | |
| import time | |
| import threading | |
| import BaseHTTPServer | |
| import SimpleHTTPServer | |
| start = time.time() | |
| run_time = 60 | |
| httpd = BaseHTTPServer.HTTPServer(('0.0.0.0', 8000), SimpleHTTPServer.SimpleHTTPRequestHandler) | |
| t = threading.Thread(target=httpd.serve_forever) | |
| t.daemon = True | |
| t.start() | |
| print('{address[0]}:{address[1]} - - Listening...'.format(address=httpd.server_address)) | |
| def shutdown(signum=None, frame=None): | |
| print('{address[0]}:{address[1]} - - Shutting down.'.format(address=httpd.server_address)) | |
| exit(0) | |
| signal.signal(signal.SIGINT, shutdown) | |
| signal.signal(signal.SIGTERM, shutdown) | |
| while time.time() - start < run_time: | |
| time.sleep(1) | |
| shutdown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment