Skip to content

Documentation unclear on proper extended usage of WriteApi client #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
markmnl opened this issue Jan 27, 2021 · 3 comments · Fixed by #218
Closed

Documentation unclear on proper extended usage of WriteApi client #190

markmnl opened this issue Jan 27, 2021 · 3 comments · Fixed by #218
Assignees
Milestone

Comments

@markmnl
Copy link

markmnl commented Jan 27, 2021

Does the WriteAPI client support context management? If so what does the context manager do - flush, close, wait for batch to complete? I cannot answer any of these queststions reading the doucmentation so I don't know if I should be creating a new instance of WriteApi client evey time I want to write a new batch..

Important: The WriteApi in batching mode (default mode) is suppose to run as a singleton. To flush all your data you should call _write_client.close() at the end of your script.

This part of the documentation I find contradictory - singleton implies never create another instance - but it goes on to say I should close to flush?? What if I have a service continuously running? How can I flush what has already been written if I want to? I don't feel confident reading the documentation using this library...

@bednar
Copy link
Contributor

bednar commented Jan 27, 2021

Hi @markmnl,

thanks for your comment.

Does the WriteAPI client support context management?

Currently not, but It is a good suggestion 👍 and we will add support for this.

If so what does the context manager do - flush, close, wait for batch to complete?

I think the context manager will close the WriteApi.

What if I have a service continuously running? How can I flush what has already been written if I want to?

Currently We don’t have an explicit flush method. 😞. I will take a look too.

Anyway thanks for your comment!

Regards

@lafrech
Copy link
Contributor

lafrech commented Feb 24, 2021

Hi.

A context manager would be really nice indeed.

It is also unclear to me the difference between write_api.close() and write_api.__del__().

Are the three following lines needed?

    write_api.close()
    write_api.__del__()
    client.__del__()

I didn't dive into the internals but it sounds very strange to call __del__ like this on an object. I never to that in Python as it should be done automatically by the garbage collector.

I wouldn't find it strange if I had to call a flush method manually, though.

Also, if close or __del__ forces the flush of the write_api, how come we also need to call __del __ on client? Is there anything else to flush?

In any case, a proper context manager should take care of all this.

@lafrech
Copy link
Contributor

lafrech commented Mar 1, 2021

Answering myself (partly).

For both InfluxDBClient and WriteApi, the close method is just a wrapper around __del__.

def close(self):
"""Flush data and dispose a batching buffer."""
self.__del__()

def close(self):
"""Shutdown the client."""
self.__del__()

I guess we should use close, then, and the docs should advertise the use of close.

Definitely something nice hiding in a context manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants