-
Notifications
You must be signed in to change notification settings - Fork 19
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
/proc/meminfo left open by functions module (GNU/Linux) #88
Comments
Thanks, @sadielbartholomew. PR #89 might be what is required. It looks like it works for me on the command line, though I wasn't getting the error. Could you try it? The background is that this function is called a huge number of times, more or less every single time a |
Thanks for the very quick response & insight. I'll try out your branch in a moment.
That makes sense! So as per your PR I see it only needs to be closed it after it has been used for the final time i.e. on exit.
That certainly explains why I throwing in a call to close in the places I tried failed. And makes me glad I asked you about it instead of going on to try to fix it in some way that could have made everything slow or downright broken! 😬
I was wondering if there was some reason I had only noticed it now, as don't recall having seen it earlier than about a week ago during the releases. I noticed this while looking into the GH Actions workflow (have some question on that actually so will tag you on that PR) & it doesn't seem to appear there either. Doing a little digging, it seems ResourceWarnings can be hidden by default, so if you try I was using Python 3.8 but I've checked & it also applies to 3.7 so the Python version probably isn't influencing in some subtle way, as with one theory I had. |
Running the test
test_dsg.py
I notice aResourceWarning
implying a file has been destroyed without first being closed:With investigation (
grep
) the origin is not from the test module but the code itself & thefunctions
module which is the only module that does IO on theproc/meminfo
file as provided in the warning (so this could potentially lead to problems in usage of cf). It is indeed opened but not closed there:cf-python/cf/functions.py
Line 96 in d8fd3c7
Naively I would think popping in a
close()
on the file after it has been used in the subsequent_free_memory()
function would be the simple fix, but trying to close it in a few obvious locations do not work, as the code still wants to use it after that point; both the commented line & the uncommented line in turn:leading to:
I was wondering about the right approach to deal with the closing of
proc/meminfo
, given it clearly needs to be done at a point when it will no longer need to be read & that precise point isn't fully obvious to me, but mostly because I am wary there may be complications, in particular looking at this comment:cf-python/cf/functions.py
Lines 90 to 93 in d8fd3c7
Ideally we could use the
with
context manager to solve this & there is in fact a comment suggesting this has been considered:cf-python/cf/functions.py
Line 126 in d8fd3c7
@davidhassell when you have time to consider this please could you advise on how best to handle this file?
The text was updated successfully, but these errors were encountered: