From f83cf8d1bb20f2318e04c4dd87b6e44183da8b83 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 22 Nov 2017 17:31:09 +0800 Subject: [PATCH] artiq_influxdb: use aiohttp.ClientSession. Closes #829 --- artiq/frontend/artiq_influxdb.py | 40 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/artiq/frontend/artiq_influxdb.py b/artiq/frontend/artiq_influxdb.py index 7205e0e4ef..ca9c3f3438 100755 --- a/artiq/frontend/artiq_influxdb.py +++ b/artiq/frontend/artiq_influxdb.py @@ -94,26 +94,26 @@ def update(self, k, v): "too many pending updates", k) async def _do(self): - while True: - k, v, t = await self._queue.get() - url = self.base_url + "/write" - params = {"u": self.user, "p": self.password, "db": self.database, - "precision": "ms"} - data = "{},dataset={} {} {}".format( - self.table, k, format_influxdb(v), round(t*1e3)) - try: - response = await aiohttp.request( - "POST", url, params=params, data=data) - except: - logger.warning("got exception trying to update '%s'", - k, exc_info=True) - else: - if response.status not in (200, 204): - content = (await response.content.read()).decode().strip() - logger.warning("got HTTP status %d " - "trying to update '%s': %s", - response.status, k, content) - response.close() + async with aiohttp.ClientSession() as session: + while True: + k, v, t = await self._queue.get() + url = self.base_url + "/write" + params = {"u": self.user, "p": self.password, "db": self.database, + "precision": "ms"} + data = "{},dataset={} {} {}".format( + self.table, k, format_influxdb(v), round(t*1e3)) + try: + response = await session.post(url, params=params, data=data) + except: + logger.warning("got exception trying to update '%s'", + k, exc_info=True) + else: + if response.status not in (200, 204): + content = (await response.content.read()).decode().strip() + logger.warning("got HTTP status %d " + "trying to update '%s': %s", + response.status, k, content) + response.close() class _Mock: