Skip to content
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

Close file handles in ffdec.py #68

Merged
merged 3 commits into from
Jun 28, 2018
Merged

Close file handles in ffdec.py #68

merged 3 commits into from
Jun 28, 2018

Conversation

RyanMarcus
Copy link
Contributor

Hello!

Thanks for all the hard work putting this library together! It made quickly combining two audio files I had super easy.

This PR just closes the /dev/null, stdout, and stderr FDs when in FFmpeg mode to avoid resource leak warnings.

Let me know if there are any issues,

Ryan

Copy link
Member

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

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

Thanks for adding these! This looks good to me. I left some notes here about where comments and formatting might be useful.

@@ -264,12 +264,14 @@ def close(self):
# ffmpeg closes normally on its own, but never updates
# `returncode`.
self.proc.poll()
self.proc.stdout.close()
self.proc.stderr.close()
Copy link
Member

Choose a reason for hiding this comment

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

The comment above doesn't apply to these lines, so it would be nice to use a blank line above them—and to write a new comment explaining why these are here. (For posterity, for example, we might want to record why this goes above the if block that happens next.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done -- left a brief note.


# Kill the process if it is still running.
if self.proc.returncode is None:
self.proc.kill()
self.proc.wait()
self.devnull.close()
self.devnull.close()
Copy link
Member

Choose a reason for hiding this comment

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

Again, since this is separate from the above handling of the subprocess, it would be a good idea to put a blank line above this one. I'm not sure if an explanatory comment would be useful to say something about why this is necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a comment anyway -- feel free to remove it if you believe it is too verbose. :)

@sampsyo
Copy link
Member

sampsyo commented Jun 27, 2018

So we can refer back to it later, what sort of resource leak warnings were you getting? Are they Python messages? Or something from ffmpeg?

@RyanMarcus
Copy link
Contributor Author

The errors were Python errors, coming from an execution of a unit test with python3 -m unittest. I think it enables these sorts of warning if an FD is left open after a test finishes.

I will copy/paste an error later tonight.

@sampsyo sampsyo merged commit 0ec91ea into beetbox:master Jun 28, 2018
sampsyo added a commit that referenced this pull request Jun 28, 2018
Close file handles in ffdec.py
sampsyo added a commit that referenced this pull request Jun 28, 2018
@sampsyo
Copy link
Member

sampsyo commented Jun 28, 2018

Awesome; thanks for clarifying! I merged the changes. ✨

@ssssam
Copy link
Contributor

ssssam commented Dec 25, 2018

This change is triggering a segfault in Beets, see #62

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants