From f09c0393bae96fbc3ad5b2150f1f472e16f8bac4 Mon Sep 17 00:00:00 2001 From: Yun Xu Date: Sat, 25 Nov 2017 21:01:22 -0800 Subject: [PATCH 1/3] adopt new websockets interface --- sanic/server.py | 2 +- sanic/worker.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index a475fd98..0efcfd05 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -635,7 +635,7 @@ def serve(host, port, request_handler, error_handler, before_start=None, coros = [] for conn in connections: if hasattr(conn, "websocket") and conn.websocket: - coros.append(conn.websocket.close_connection(force=True)) + coros.append(conn.websocket.close_connection(after_handshake=True)) else: conn.close() diff --git a/sanic/worker.py b/sanic/worker.py index 79c0a17d..6de18159 100644 --- a/sanic/worker.py +++ b/sanic/worker.py @@ -115,7 +115,7 @@ class GunicornWorker(base.Worker): coros = [] for conn in self.connections: if hasattr(conn, "websocket") and conn.websocket: - coros.append(conn.websocket.close_connection(force=True)) + coros.append(conn.websocket.close_connection(after_handshake=False)) else: conn.close() _shutdown = asyncio.gather(*coros, loop=self.loop) From 049f12096d6cb40726bf4d68a9c98ed0438f8512 Mon Sep 17 00:00:00 2001 From: Yun Xu Date: Sat, 25 Nov 2017 21:07:38 -0800 Subject: [PATCH 2/3] fix unit tests --- setup.py | 2 +- tests/test_worker.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 17f2c67e..3f8cd7ce 100644 --- a/setup.py +++ b/setup.py @@ -59,7 +59,7 @@ requirements = [ uvloop, ujson, 'aiofiles>=0.3.0', - 'websockets>=3.2', + 'websockets>=4.0', ] if strtobool(os.environ.get("SANIC_NO_UJSON", "no")): print("Installing without uJSON") diff --git a/tests/test_worker.py b/tests/test_worker.py index e2b301ec..af00982e 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -131,5 +131,5 @@ def test_worker_close(worker): loop.run_until_complete(_close) assert worker.signal.stopped == True - conn.websocket.close_connection.assert_called_with(force=True) + conn.websocket.close_connection.assert_called_with(after_handshake=False) assert len(worker.servers) == 0 From 076f0515cab9d17da7e004e58c1e2443cf17de63 Mon Sep 17 00:00:00 2001 From: Yun Xu Date: Sat, 25 Nov 2017 21:14:18 -0800 Subject: [PATCH 3/3] Fix flake8 --- sanic/server.py | 4 +++- sanic/worker.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index 0efcfd05..d50842b9 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -635,7 +635,9 @@ def serve(host, port, request_handler, error_handler, before_start=None, coros = [] for conn in connections: if hasattr(conn, "websocket") and conn.websocket: - coros.append(conn.websocket.close_connection(after_handshake=True)) + coros.append( + conn.websocket.close_connection(after_handshake=True) + ) else: conn.close() diff --git a/sanic/worker.py b/sanic/worker.py index 6de18159..3d8a4617 100644 --- a/sanic/worker.py +++ b/sanic/worker.py @@ -115,7 +115,9 @@ class GunicornWorker(base.Worker): coros = [] for conn in self.connections: if hasattr(conn, "websocket") and conn.websocket: - coros.append(conn.websocket.close_connection(after_handshake=False)) + coros.append( + conn.websocket.close_connection(after_handshake=False) + ) else: conn.close() _shutdown = asyncio.gather(*coros, loop=self.loop)