-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix file descriptor leak #32598
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
BUG: Fix file descriptor leak #32598
Conversation
@@ -314,3 +316,15 @@ def test_malformed_skipfooter(python_parser_only): | |||
msg = "Expected 3 fields in line 4, saw 5" | |||
with pytest.raises(ParserError, match=msg): | |||
parser.read_csv(StringIO(data), header=1, comment="#", skipfooter=1) | |||
|
|||
|
|||
def test_file_descriptor_leak(python_parser_only): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we also test this against the C parser (and use the all_parsers
fixture instead)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, done.
def test_file_descriptor_leak(python_parser_only): | ||
# GH 31488 | ||
parser = python_parser_only | ||
with open("empty.csv", "w"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we try using our ensure_clean utility instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
proc = psutil.Process() | ||
with pytest.raises(EmptyDataError): | ||
parser.read_csv("empty.csv") | ||
assert not proc.open_files() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would check that the list of open files does not contain our file, not that it's empty (more vulnerable to failure if the testing environment happens to have other files open unrelated to our test).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have now changed the test to a before/after check that triggers when the results differ.
pass | ||
|
||
proc = psutil.Process() | ||
with pytest.raises(EmptyDataError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the error message as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
0e5012f
to
830ed1d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks good just some standardization on the test that can be improved
# GH 31488 | ||
import psutil | ||
|
||
proc = psutil.Process() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment here very similar to what you posted above (e.g. why using psutil open files to check)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
830ed1d
to
bc238a0
Compare
Also add a comment why combining tm.ensure_clean and td.check_file_leaks don't play along nicely together
bc238a0
to
d08bc10
Compare
thanks @roberthdevries |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff