diff --git a/asynchttp/worker.py b/asynchttp/worker.py index 80cba5e56c..57ee4f01ea 100644 --- a/asynchttp/worker.py +++ b/asynchttp/worker.py @@ -30,9 +30,14 @@ def factory(self): @tulip.coroutine def _run(self): - servers = [ - self.loop.create_server(self.factory, sock=sock.sock) - for sock in self.sockets] + servers = [] + def add_server(t): + servers.append(t.result()) + + for sock in self.sockets: + t = tulip.async( + self.loop.create_server(self.factory, sock=sock.sock)) + t.add_done_callback(add_server) # If our parent changed then we shut down. pid = os.getpid() diff --git a/tests/worker_test.py b/tests/worker_test.py index a8592ba5a6..7306fb01b2 100644 --- a/tests/worker_test.py +++ b/tests/worker_test.py @@ -50,7 +50,8 @@ def test_factory(self): self.assertIsInstance(f, WSGIServerHttpProtocol) - def test__run(self): + @unittest.mock.patch('asynchttp.worker.tulip') + def test__run(self, m_tulip): self.worker.ppid = 1 self.worker.alive = True self.worker.sockets = [unittest.mock.Mock()]