1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00

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.
This commit is contained in:
Andy Hayden 2018-09-25 18:39:04 -07:00 committed by Ryan Dahl
parent ef41a1ab2b
commit bf93ca54dd

View file

@ -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()