From 29181b158661990e0c35e7ef9d66f4b5fca90135 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 7205e0e4e..ca9c3f343 100755 --- a/artiq/frontend/artiq_influxdb.py +++ b/artiq/frontend/artiq_influxdb.py @@ -94,26 +94,26 @@ class DBWriter(TaskObject): "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: