Get and write datapoints concurrently

Hello!

I’m trying to concurrently and indefinitely get datapoints and write them to influxDB using Python Client, but I’m missing something.

Innitially, I collected the datapoints into a list and if there is any datapoint I would write those into DB. However, new datapoint were not being appended to the list while the datapoint batch was being written to the DB, which could take some 300ms.

I tried to use asyncio to overcome this issue, but unfortunately it’s not working.

Below an example of what I’m doing:

import asyncio
from influxdb_client import WritePrecision, Point, WriteOptions
from influxdb_client.client.influxdb_client_async import InfluxDBClientAsync

bucket = "bucket"
org = "org"
token = "token"
url = "http://localhost:8086"

p = []

async def write_points():
    while True:
        if p:
            points = p.copy()
            p.clear()
            async with InfluxDBClientAsync(url=url, token=token, org=org) as client:
                write_client = client.write_api()
                await write_client.write(bucket, org, points, write_precision=WritePrecision.MS)

async def get_points():
    while True:
        if datapoint:
            await p.append(datapoint) # Get data points as they are presented. The data point acqisition interval can randomly vary from 1ms to 1s

loop = asyncio.get_event_loop()
asyncio.ensure_future(get_points())
asyncio.ensure_future(write_points())
loop.run_forever()

What am I doing wrong? Is there any other way of doing it?

Thank you!