web: serve script for lab
This commit is contained in:
parent
cc6505cae9
commit
3a38dd4737
2 changed files with 30 additions and 0 deletions
29
docs/lab/serve.py
Executable file
29
docs/lab/serve.py
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env python
|
||||
from __future__ import print_function, absolute_import
|
||||
import os, sys
|
||||
import signal
|
||||
import SimpleHTTPServer
|
||||
import socket
|
||||
import SocketServer
|
||||
|
||||
def sighandler(signum, frame):
|
||||
sys.stdout.write('\n')
|
||||
sys.stdout.flush()
|
||||
sys.exit(1)
|
||||
|
||||
class TCPServer(SocketServer.TCPServer):
|
||||
def server_bind(self):
|
||||
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
self.socket.bind(self.server_address)
|
||||
|
||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
# make ^C instantly exit program
|
||||
signal.signal(signal.SIGINT, sighandler)
|
||||
|
||||
httpd = TCPServer(
|
||||
("127.0.0.1", 3002),
|
||||
SimpleHTTPServer.SimpleHTTPRequestHandler)
|
||||
|
||||
print("serving at http://localhost:3002/")
|
||||
httpd.serve_forever()
|
||||
Reference in a new issue