diff options
author | Andy Hayden <andyhayden1@gmail.com> | 2018-09-25 18:39:04 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-09-27 15:49:43 -0400 |
commit | bf93ca54dd85686c7b93a6189913e48e10de8dcf (patch) | |
tree | 877c7b8ee449aeb8de0ea6386c4afc1d08814bdc /tools/http_server.py | |
parent | ef41a1ab2bd9190058944842644738808e266cb6 (diff) |
Ensure spawning python server twice raises an exception.
Previously it would dump the traceback but not raise.
It's unclear if serve_forever could crash for some other reason,
but the main reason spawn throws is if the port is already in use.
Diffstat (limited to 'tools/http_server.py')
-rwxr-xr-x | tools/http_server.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/tools/http_server.py b/tools/http_server.py index f8c77f08b..fdb8686cd 100755 --- a/tools/http_server.py +++ b/tools/http_server.py @@ -11,17 +11,18 @@ from time import sleep PORT = 4545 -def serve_forever(): +def server(): os.chdir(root_path) # Hopefully the main thread doesn't also chdir. Handler = SimpleHTTPServer.SimpleHTTPRequestHandler SocketServer.TCPServer.allow_reuse_address = True - httpd = SocketServer.TCPServer(("", PORT), Handler) + s = SocketServer.TCPServer(("", PORT), Handler) print "Deno test server http://localhost:%d/" % PORT - httpd.serve_forever() + return s def spawn(): - thread = Thread(target=serve_forever) + s = server() + thread = Thread(target=s.serve_forever) thread.daemon = True thread.start() sleep(1) # TODO I'm too lazy to figure out how to do this properly. @@ -29,4 +30,5 @@ def spawn(): if __name__ == '__main__': - serve_forever() + s = server() + s.serve_forever() |