Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dvc/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def _spawn_posix(cmd, env):
sys.stdin.close()
sys.stdout.close()
sys.stderr.close()
os.closerange(0, 3)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this line fixes the problem? Usually the first 3 fds are stdin/stdout/stderr, are you sure this line is doing anything?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe stdin/stdout/stderr are not really fds 0, 1, 2 Could you check?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first thing that I tried to fix this was:

sys.stdin = None
sys.stdout = None
sys.stderr = None

And 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. :)

Copy link
Copy Markdown
Collaborator Author

@skshetry skshetry Mar 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe stdin/stdout/stderr are not really fds 0, 1, 2 Could you check?

No, they are 0, 1, and 2.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh i don't know what I am doing here. I am also surprised that this fixes the issue. :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So looks like sys.* is python level and doesn't necessarily close underlying filedescriptors. I guess that explains this change.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I searched everywhere but could not get a hint. Thank you for the link. 🙏🏼


if platform.system() == "Darwin":
# workaround for MacOS bug
Expand Down