From 40d0bf27a6a629f83d83f13f5bd7c827ea93ffcc Mon Sep 17 00:00:00 2001 From: Tyson Clugg Date: Mon, 14 Dec 2015 13:07:25 +1100 Subject: [PATCH] Fail on start if any child threads can't start. --- CHANGES.rst | 1 + dddp/main.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index b110bb5..d31637a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -11,6 +11,7 @@ develop `python_platform_implementation` environment marker. * Moved repository to https://github.com/django-ddp/django-ddp (new Github organisation). +* Fail on start if any child threads can't start (eg: port in use). * Add missing versions and dates to the change log, and note on Semantic Versioning. * Back to universal wheels, thanks to PEP-0496 environment markers. diff --git a/dddp/main.py b/dddp/main.py index 577d86d..f4783a5 100644 --- a/dddp/main.py +++ b/dddp/main.py @@ -207,7 +207,12 @@ class DDPLauncher(object): self.print('=> Started PostgresGreenlet.') for server in self.servers: thread = gevent.spawn(server.serve_forever) + gevent.sleep() # yield to thread in case it can't start self.threads.append(thread) + if thread.dead: + # thread died, stop everything and re-raise the exception. + self.stop() + thread.get() if isinstance(server, geventwebsocket.WebSocketServer): self.print( '=> App running at: %s://%s:%d/' % (