mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -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:
parent
ef41a1ab2b
commit
bf93ca54dd
1 changed files with 7 additions and 5 deletions
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue