Skip to content

Instantly share code, notes, and snippets.

@brettvitaz
Last active September 16, 2015 18:38
Show Gist options
  • Select an option

  • Save brettvitaz/240e190accec3a00e9d1 to your computer and use it in GitHub Desktop.

Select an option

Save brettvitaz/240e190accec3a00e9d1 to your computer and use it in GitHub Desktop.
Start a temporary HTTP to serve a quick file and bail.
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