From 1d3abd8c570eb66e2fcc9c0b297c9d2a9153c7a3 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Wed, 26 Jul 2017 11:51:31 +0200 Subject: [PATCH] Fix: ClientResponse.close() is not a coroutine --- aiodocker/docker.py | 13 ++++++------- aiodocker/jsonstream.py | 2 +- tests/test_integration.py | 2 ++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/aiodocker/docker.py b/aiodocker/docker.py index 9cd2d4ebb..38db81b2f 100644 --- a/aiodocker/docker.py +++ b/aiodocker/docker.py @@ -522,16 +522,15 @@ async def run(self, **params): self._transform_event, human_bool(params['stream']), ) - async for data in self.json_stream: - await self.channel.publish(data) + try: + async for data in self.json_stream: + await self.channel.publish(data) + finally: + await self.json_stream.close() + self.json_stream = None finally: # signal termination to subscribers await self.channel.publish(None) - try: - await self.json_stream.close() - except: - pass - self.json_stream = None async def stop(self): if self.json_stream is not None: diff --git a/aiodocker/jsonstream.py b/aiodocker/jsonstream.py index 03d904a1a..77b391e41 100644 --- a/aiodocker/jsonstream.py +++ b/aiodocker/jsonstream.py @@ -42,7 +42,7 @@ async def close(self): # (see https://github.com/KeepSafe/aiohttp/issues/739) # response error , it has been closed - await self._response.close() + self._response.close() async def json_stream_result(response, transform=None, stream=True): diff --git a/tests/test_integration.py b/tests/test_integration.py index 78efb835c..a6db4d871 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -231,3 +231,5 @@ async def test_events(docker, testing_images, event_loop): break assert events_occurred == ['create', 'start', 'kill', 'die', 'destroy'] + + await docker.events.stop()