Skip to content

Commit bc12a98

Browse files
test: add multiprocess helper test
1 parent 53ed6ce commit bc12a98

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

influxdb_client_3/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,10 @@ def flush(self):
740740

741741
def close(self):
742742
"""Close the client and clean up resources."""
743-
self._write_api.close()
744-
self._query_api.close()
743+
if self._write_api is not None:
744+
self._write_api.close()
745+
if self._query_api is not None:
746+
self._query_api.close()
745747

746748
def __enter__(self):
747749
return self

influxdb_client_3/write_client/client/util/multiprocessing_helper.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,16 @@ def run(self):
154154
error_callback=self.kwargs.get('error_callback', _error_callback),
155155
retry_callback=self.kwargs.get('retry_callback', _retry_callback)
156156
)
157+
158+
# Still need to create the InfluxDBClient3 because the init logics of InfluxDBClient3 will create the WriteApi.
159+
# it will make WriteApi class created properly.
157160
self.client = InfluxDBClient3(write_client_options=wco, **self.kwargs)
161+
162+
# Close and set _query_api to None because query_api is not needed in this process.
163+
# We only need write_api.
164+
self.client._query_api.close()
165+
self.client._query_api = None
166+
158167
self.write_api = self.client._write_api
159168
# Infinite loop - until poison pill
160169
while True:

0 commit comments

Comments
 (0)