From 7d9d48e299139b7a8d6c76d55d3fd5e28d34dd99 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sat, 26 Aug 2017 09:50:35 +0300 Subject: [PATCH 1/3] Call shutdown_asyncgens before loop closing --- aiohttp/web.py | 1 + aiohttp/worker.py | 1 + 2 files changed, 2 insertions(+) diff --git a/aiohttp/web.py b/aiohttp/web.py index abbc096cda0..a40894bc320 100644 --- a/aiohttp/web.py +++ b/aiohttp/web.py @@ -464,6 +464,7 @@ def run_app(app, *, host=None, port=None, path=None, sock=None, finally: loop.run_until_complete(app.cleanup()) if not user_supplied_loop: + loop.run_until_complete(loop.shutdown_asyncgens()) loop.close() diff --git a/aiohttp/worker.py b/aiohttp/worker.py index 212f1b1bb2c..7df9ce21be7 100644 --- a/aiohttp/worker.py +++ b/aiohttp/worker.py @@ -48,6 +48,7 @@ def run(self): try: self.loop.run_until_complete(self._runner) finally: + self.loop.run_until_complete(self.loop.shutdown_asyncgens()) self.loop.close() sys.exit(self.exit_code) From 8648fe665df89523863f0b556fc6d1e7802e0451 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sat, 26 Aug 2017 10:54:31 +0300 Subject: [PATCH 2/3] Check for shutdown_asyncgens existance --- aiohttp/web.py | 3 ++- aiohttp/worker.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/aiohttp/web.py b/aiohttp/web.py index a40894bc320..6caee4ce10d 100644 --- a/aiohttp/web.py +++ b/aiohttp/web.py @@ -464,7 +464,8 @@ def run_app(app, *, host=None, port=None, path=None, sock=None, finally: loop.run_until_complete(app.cleanup()) if not user_supplied_loop: - loop.run_until_complete(loop.shutdown_asyncgens()) + if hasattr(loop, 'shutdown_asyncgens'): + loop.run_until_complete(loop.shutdown_asyncgens()) loop.close() diff --git a/aiohttp/worker.py b/aiohttp/worker.py index 7df9ce21be7..a52f58f7129 100644 --- a/aiohttp/worker.py +++ b/aiohttp/worker.py @@ -48,7 +48,8 @@ def run(self): try: self.loop.run_until_complete(self._runner) finally: - self.loop.run_until_complete(self.loop.shutdown_asyncgens()) + if hasattr(self.loop, 'shutdown_asyncgens'): + self.loop.run_until_complete(self.loop.shutdown_asyncgens()) self.loop.close() sys.exit(self.exit_code) From 12c7b6a8534a84261e000b90833929dce4d1e25a Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sat, 26 Aug 2017 12:37:17 +0300 Subject: [PATCH 3/3] Add changes --- changes/2227.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/2227.feature diff --git a/changes/2227.feature b/changes/2227.feature new file mode 100644 index 00000000000..d09ea90dd21 --- /dev/null +++ b/changes/2227.feature @@ -0,0 +1 @@ +Call `shutdown_asyncgens` before event loop closing on Python 3.6.