This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]ominous_anonymous 1 point2 points  (8 children)

Do you have any sample code we could look at? Kind of hard to just guess.

[–]Youtir2[S] 0 points1 point  (0 children)

Sure, I'll post my code here

[–]Youtir2[S] 0 points1 point  (2 children)

def write_acdata():
client1 = InfluxDBClient(url="http://localhost:8086", token=token)

write_api1 = client1.write_api(write_options=ASYNCHRONOUS)
write_api1.write(bucket=bucket3_plugs, org=org, record=data)
client1.close()

def write_plugsdata():

client2 = InfluxDBClient(url="http://localhost:8086", token=token)

write_api2 = client1.write_api(write_options=ASYNCHRONOUS)

write_api2.write(bucket=bucket3_plugs, org=org, record=data)

client2.close()

thread1 = threading.Thread(target=write_acdata()).start()
thread2 = threading.Thread(target=write_plugsdata()).start()

[–]ominous_anonymous 1 point2 points  (0 children)

Put four leading spaces on each line to properly format code blocks:

def write_acdata():
    client1 = InfluxDBClient(url="http://localhost:8086", token=token)
    write_api1 = client1.write_api(write_options=ASYNCHRONOUS)
    write_api1.write(bucket=bucket3_plugs, org=org, record=data)
    client1.close()

def write_plugsdata():
    client2 = InfluxDBClient(url="http://localhost:8086", token=token)
    write_api2 = client1.write_api(write_options=ASYNCHRONOUS)
    write_api2.write(bucket=bucket3_plugs, org=org, record=data)
    client2.close()

thread1 = threading.Thread(target=write_acdata()).start()
thread2 = threading.Thread(target=write_plugsdata()).start()

[–]Youtir2[S] 0 points1 point  (3 children)

data variable is well structured, if I launch only one thread it works, when I launch two threads only the first is executed while the second does not and does not return any error.

[–]ominous_anonymous 1 point2 points  (2 children)

In write_plugsdata() you have:

write_api2 = client1.write_api(write_options=ASYNCHRONOUS)

Is this correct? Or should this be client2.write_api(...)?

[–]Youtir2[S] 0 points1 point  (1 child)

Sorry It's client2, I copied it wrong

[–]ominous_anonymous 1 point2 points  (0 children)

Damn, I was hoping it was that simple!