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

Clean up running spotify instances when removed from configuration (#564) #565

Merged
merged 1 commit into from
Dec 12, 2023

Conversation

rtertiaer
Copy link
Contributor

This PR fixes #564 , as well as cleans up a couple of things. The bug #564 was that even when a spotify stream was deleted from the configuration, it ran in the background. This was due to the Spotify(PersistentStream) class overriding PersistentStream's __del__. I've removed Spotify's __del__; it appears to be detritus from before it was a PersistentStream.

@@ -284,6 +284,7 @@ def disconnect(self):
try:
# must use terminate as kill() cannot be intercepted
self._cproc.terminate()
self._cproc.communicate(timeout=5)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

terminate() just fires off a signal; communicate actually prevents zombies from piling up. Doing things this way can also more appropriately bubble up errors caught during a timeout exception. This was ultimately not the cause of the issue tho, just a worthy improvement.

@@ -511,7 +512,6 @@ def __init__(self, name: str, disabled: bool = False, mock: bool = False):

self.connect_port: Optional[int] = None
self.mpris: Optional[MPRIS] = None
self.proc_pid: Optional[int] = None
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is unused.

Comment on lines -527 to -529
def __del__(self):
self.disconnect()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the actual bugfix.

Comment on lines +572 to +576
self.proc.terminate()
outs, errs = self.proc.communicate(timeout=3)
except Exception as e:
print(f"failed to terminate spotify stream: {e}")
kouts, kerrs = self.proc.kill()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above - just improved process handling.

Copy link
Contributor

@linknum23 linknum23 left a comment

Choose a reason for hiding this comment

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

This makes a lot of sense. Should we "robustify" other streams using the terminate/communicate paradigm also?

Nice catch.

@rtertiaer rtertiaer merged commit ace822f into develop Dec 12, 2023
2 of 3 checks passed
@rtertiaer rtertiaer deleted the clean_up_spotify_on_del branch December 12, 2023 17:17
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.

None yet

2 participants