close streams#9204
Conversation
Codecov ReportPatch and project coverage have no change.
Additional details and impacted files@@ Coverage Diff @@
## main #9204 +/- ##
=======================================
Coverage 92.88% 92.89%
=======================================
Files 457 457
Lines 36938 36954 +16
Branches 5334 5339 +5
=======================================
+ Hits 34311 34328 +17
Misses 2100 2100
+ Partials 527 526 -1
... and 3 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
I can confirm: |
| sys.stdin.close() | ||
| sys.stdout.close() | ||
| sys.stderr.close() | ||
| os.closerange(0, 3) |
There was a problem hiding this comment.
Hm, this line fixes the problem? Usually the first 3 fds are stdin/stdout/stderr, are you sure this line is doing anything?
There was a problem hiding this comment.
yes, that's what surprises me. It's as if close() is not working, maybe they are not really closed until the interpreter shuts down? Idk.
There was a problem hiding this comment.
Or maybe stdin/stdout/stderr are not really fds 0, 1, 2 Could you check?
There was a problem hiding this comment.
The first thing that I tried to fix this was:
sys.stdin = None
sys.stdout = None
sys.stderr = NoneAnd it magically worked. So I thought maybe there was a garbage collection issue.
But, adding gc.collect() did not fix it. Then I went to os.close() for code clarity. :)
There was a problem hiding this comment.
Or maybe stdin/stdout/stderr are not really fds 0, 1, 2 Could you check?
No, they are 0, 1, and 2.
There was a problem hiding this comment.
Tbh i don't know what I am doing here. I am also surprised that this fixes the issue. :)
There was a problem hiding this comment.
Looks like you are not first to run into this https://code.activestate.com/recipes/186101-really-closing-stdin-stdout-stderr/
There was a problem hiding this comment.
So looks like sys.* is python level and doesn't necessarily close underlying filedescriptors. I guess that explains this change.
There was a problem hiding this comment.
hmm, I searched everywhere but could not get a hint. Thank you for the link. 🙏🏼
I have been seeing weird perf issue when the output was being redirected:
I could not find an issue why it would take so long, but my suspicion was that the stdin to the
lesswas not being closed for some reason. So I tried addingos.close()and it was fast again.I was not able to find an issue regarding this on Cpython, and I would love if I could get confirmation of the bug from other team members as well.
The
dvc doctoroutput is: