Ensure that PKC signals playback stop on shutdown

This commit is contained in:
croneter 2017-12-14 15:54:28 +01:00
parent 502c013af0
commit 7100802cab
2 changed files with 16 additions and 2 deletions

View file

@ -157,11 +157,14 @@ class PlexCompanion(Thread):
def run(self):
"""
Ensure that sockets will be closed no matter what
Ensure that
- STOP sent to PMS
- sockets will be closed no matter what
"""
try:
self._run()
finally:
self.subscription_manager.signal_stop()
try:
self.httpd.socket.shutdown(SHUT_RDWR)
except AttributeError:
@ -184,6 +187,7 @@ class PlexCompanion(Thread):
request_mgr = httppersist.RequestMgr()
subscription_manager = subscribers.SubscriptionMgr(
request_mgr, self.player, self.mgr)
self.subscription_manager = subscription_manager
queue = Queue(maxsize=100)
self.queue = queue

View file

@ -98,6 +98,16 @@ class SubscriptionMgr(object):
LOG.debug('msg is: %s', msg)
return msg
def signal_stop(self):
"""
Externally called on PKC shutdown to ensure that PKC signals a stop to
the PMS. Otherwise, PKC might be stuck at "currently playing"
"""
LOG.info('Signaling a complete stop to PMS')
for _, player in self.lastplayers.iteritems():
self.last_params['state'] = 'stopped'
self._send_pms_notification(player['playerid'], self.last_params)
def _get_container_key(self, playerid):
key = None
playlistid = state.PLAYER_STATES[playerid]['playlistid']
@ -233,7 +243,7 @@ class SubscriptionMgr(object):
except KeyError:
pass
# Process the players we have left (to signal a stop)
for typus, player in self.lastplayers.iteritems():
for _, player in self.lastplayers.iteritems():
self.last_params['state'] = 'stopped'
self._send_pms_notification(player['playerid'], self.last_params)