ARROW-1768: [Python] Fix suppressed exception in ParquetWriter.__del__#1286
Closed
Licht-T wants to merge 2 commits intoapache:masterfrom
Closed
ARROW-1768: [Python] Fix suppressed exception in ParquetWriter.__del__#1286Licht-T wants to merge 2 commits intoapache:masterfrom
Licht-T wants to merge 2 commits intoapache:masterfrom
Conversation
cpcloud
requested changes
Nov 5, 2017
python/pyarrow/parquet.py
Outdated
| {0} | ||
| """.format(_parquet_writer_arg_docs) | ||
|
|
||
| is_open = False |
Contributor
There was a problem hiding this comment.
I don't think this is the correct solution. It looks like we're defining __del__ which will be called if __init__ raises an exception. If __init__ raises an exception before defining self.is_open then you'll get an AttributeError exception in __del__ when it's called.
We really should not be opening files in constructors, since Python doesn't have the same guarantees as C++ around resource initialization and destruction. We should be using a context manager here since that provides clear semantics and guarantees when __enter__ and __exit__ will run.
For now, though, can you do this instead?
def __del__(self):
if getattr(self, 'is_open', False):
self.close()Change-Id: I08f5e533205214de74f340dec2cfd84931782ad0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This closes ARROW-1768.