Skip to content

Commit 62d2cfc

Browse files
committed
docs: update example to illustrate error callbacks.
1 parent 22c9b8e commit 62d2cfc

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Examples/timeouts.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import sys
33
import time
44

5-
from influxdb_client_3 import InfluxDBClient3
6-
5+
from influxdb_client_3 import InfluxDBClient3, write_client_options
76

87
"""
98
This example shows how to set query and write timeouts.
@@ -23,6 +22,10 @@
2322
DEFAULT_DATABASE = 'test-data'
2423

2524

25+
def handle_write_error_cb(rd, rt, rx):
26+
print(f"Got a write error: {rd}, {rt}, {rx}")
27+
28+
2629
def main(w_to: int, q_to: int) -> None:
2730
print(f"main {w_to}, {q_to}")
2831
lp_data = "timeout_example,location=terra fVal=3.14,iVal=42i"
@@ -31,7 +34,10 @@ def main(w_to: int, q_to: int) -> None:
3134
token=DEFAULT_TOKEN,
3235
database=DEFAULT_DATABASE,
3336
write_timeout=w_to,
34-
query_timeout=q_to
37+
query_timeout=q_to,
38+
write_client_options=write_client_options(
39+
error_handler=handle_write_error_cb
40+
)
3541
) as client:
3642

3743
try:
@@ -64,6 +70,7 @@ def main(w_to: int, q_to: int) -> None:
6470
print(f"Got exception on query: {e}")
6571

6672

73+
# To force timeout errors supply the corresponding command line arguments
6774
if __name__ == "__main__":
6875
w_ct = DEFAULT_WRITE_TIMEOUT
6976
q_ct = DEFAULT_QUERY_TIMEOUT

0 commit comments

Comments
 (0)