Closing consumer multiple times should not raise RunTimeError #678
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current behavior is to raise a
RunTimeError
ifconsumer.close
is called more than once.This proposed change makes
close
rerunnable by not raisingRunTimeError
if it is called more than once.This will make it convenient for developers to safely call consumer.close in a
finally
or a context manager without having to trap this exception.The use case is to make
close
rerunnable, for example if you wanted to make a context manager, or if you had a large function wrapped in a try/except/finally. Another programmer who calls your context manager can close inside if he wants; otherwise the context manager will close for him.I'm also under the impression that the majority of the other python libraries that close resources also make close rerunnable. I think it would be a good idea to have confluent_kafka follow this pattern.