Correclty cleanup packet capture objects when closing server

Fix #592
This commit is contained in:
Julien Duponchelle
2016-08-19 11:05:54 +02:00
parent 8eab94f01e
commit f0fad5289c
5 changed files with 30 additions and 13 deletions

View File

@ -295,11 +295,24 @@ class Compute:
:returns: A file stream
"""
# Due to Python 3.4 limitation we can't use with and asyncio
# https://www.python.org/dev/peps/pep-0492/
# that why we wrap the answer
class StreamResponse:
def __init__(self, response):
self._response = response
def __enter__(self):
return self._response.content
def __exit__(self):
self._response.close()
url = self._getUrl("/projects/{}/stream/{}".format(project.id, path))
response = yield from self._session().request("GET", url, auth=self._auth)
if response.status == 404:
raise aiohttp.web.HTTPNotFound(text="{} not found on compute".format(path))
return response.content
return StreamResponse(response)
@asyncio.coroutine
def http_query(self, method, path, data=None, **kwargs):