[#389] Possible fix for "Too many open files" media issue.
continuous-integration/drone/push Build is passing Details

It seems that the process keeps a lot of open connections to Chromecast
devices during playback.

The most likely culprit is the `_refresh_chromecasts` logic.

We should start a `cast` object and register a status listener only if a
Chromecast with the same identifier isn't already registered in the
plugin.
This commit is contained in:
Fabio Manganiello 2024-04-15 23:01:10 +02:00
parent 027bcea612
commit 33d4c8342d
Signed by: blacklight
GPG Key ID: D90FBA7F76362774
1 changed files with 12 additions and 4 deletions

View File

@ -105,7 +105,7 @@ class MediaChromecastPlugin(MediaPlugin, RunnablePlugin):
:param callback: If blocking is false, then you can provide a callback
function that will be invoked when a new device is discovered
"""
self.chromecasts = {
casts = {
self._get_device_property(cast, 'friendly_name'): cast
for cast in self._get_chromecasts(
tries=tries,
@ -116,11 +116,18 @@ class MediaChromecastPlugin(MediaPlugin, RunnablePlugin):
)
}
for name, cast in self.chromecasts.items():
self._update_listeners(name, cast)
for name, cast in casts.copy().items():
if not self.chromecasts.get(name):
self.logger.info('Discovered new Chromecast: %s', name)
self.chromecasts[name] = cast
self._update_listeners(name, cast)
cast.wait()
else:
casts.pop(name)
for cast in self.chromecasts.values():
for name, cast in casts.items():
cast.wait()
self.logger.info('Refreshed Chromecast state: %s', name)
def _event_callback(self, _, cast: pychromecast.Chromecast):
with self._refresh_lock:
@ -133,6 +140,7 @@ class MediaChromecastPlugin(MediaPlugin, RunnablePlugin):
name=name, cast=cast, callback=self._event_callback
)
cast.media_controller.register_status_listener(self._media_listeners[name])
self.logger.debug('Started media listener for %s', name)
def get_chromecast(self, chromecast=None, n_tries=2):
if isinstance(chromecast, pychromecast.Chromecast):