Move playback startup from thread to task

This commit is contained in:
croneter 2018-11-26 07:48:45 +01:00
parent 030c381f65
commit fada7f707f
3 changed files with 16 additions and 29 deletions

View file

@ -32,8 +32,6 @@ class App(object):
# Plex Companion Queue()
self.companion_queue = Queue.Queue(maxsize=100)
# Command Pipeline Queue()
self.command_pipeline_queue = Queue.Queue()
# Websocket_client queue to communicate with librarysync
self.websocket_queue = Queue.Queue()
# xbmc.Monitor() instance from kodimonitor.py

View file

@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, unicode_literals
from logging import getLogger
from threading import Thread
from urlparse import parse_qsl
from .kodi_db import KodiVideoDB
@ -10,7 +9,7 @@ from . import playback
from . import context_entry
from . import json_rpc as js
from . import pickler
from . import app
from . import backgroundthread
###############################################################################
@ -19,12 +18,17 @@ LOG = getLogger('PLEX.playback_starter')
###############################################################################
class PlaybackStarter(Thread):
class PlaybackTask(backgroundthread.Task):
"""
Processes new plays
"""
@staticmethod
def _triage(item):
def __init__(self, command):
self.command = command
super(PlaybackTask, self).__init__()
def run(self):
LOG.debug('Starting PlaybackTask with %s', self.command)
item = self.command
try:
_, params = item.split('?', 1)
except ValueError:
@ -59,16 +63,4 @@ class PlaybackStarter(Thread):
elif mode == 'context_menu':
context_entry.ContextMenu(kodi_id=params.get('kodi_id'),
kodi_type=params.get('kodi_type'))
def run(self):
queue = app.APP.command_pipeline_queue
LOG.info("----===## Starting PlaybackStarter ##===----")
while True:
item = queue.get()
if item is None:
# Need to shutdown - initiated by command_pipeline
break
else:
self._triage(item)
queue.task_done()
LOG.info("----===## PlaybackStarter stopped ##===----")
LOG.debug('Finished PlaybackTask')

View file

@ -341,7 +341,6 @@ class Service():
self.alexa = websocket_client.Alexa_Websocket()
self.sync = sync.Sync()
self.plexcompanion = plex_companion.PlexCompanion()
self.playback_starter = playback_starter.PlaybackStarter()
self.playqueue = playqueue.PlayqueueMonitor()
# Main PKC program loop
@ -360,33 +359,30 @@ class Service():
# Commands/user interaction received from other PKC Python
# instances (default.py and context.py instead of service.py)
utils.window('plex_command', clear=True)
task = None
if plex_command.startswith('PLAY-'):
# Add-on path playback!
app.APP.command_pipeline_queue.put(
task = playback_starter.PlaybackTask(
plex_command.replace('PLAY-', ''))
elif plex_command.startswith('NAVIGATE-'):
app.APP.command_pipeline_queue.put(
task = playback_starter.PlaybackTask(
plex_command.replace('NAVIGATE-', ''))
elif plex_command.startswith('CONTEXT_menu?'):
app.APP.command_pipeline_queue.put(
task = playback_starter.PlaybackTask(
'dummy?mode=context_menu&%s'
% plex_command.replace('CONTEXT_menu?', ''))
elif plex_command == 'choose_pms_server':
task = backgroundthread.FunctionAsTask(
self.choose_pms_server, None)
backgroundthread.BGThreader.addTasksToFront([task])
elif plex_command == 'switch_plex_user':
task = backgroundthread.FunctionAsTask(
self.switch_plex_user, None)
backgroundthread.BGThreader.addTasksToFront([task])
elif plex_command == 'enter_new_pms_address':
task = backgroundthread.FunctionAsTask(
self.enter_new_pms_address, None)
backgroundthread.BGThreader.addTasksToFront([task])
elif plex_command == 'toggle_plex_tv_sign_in':
task = backgroundthread.FunctionAsTask(
self.toggle_plex_tv, None)
backgroundthread.BGThreader.addTasksToFront([task])
elif plex_command == 'repair-scan':
app.SYNC.run_lib_scan = 'repair'
elif plex_command == 'full-scan':
@ -397,6 +393,8 @@ class Service():
app.SYNC.run_lib_scan = 'textures'
elif plex_command == 'RESET-PKC':
utils.reset()
if task:
backgroundthread.BGThreader.addTasksToFront([task])
continue
if app.APP.suspend:
@ -446,7 +444,6 @@ class Service():
self.ws.start()
self.sync.start()
self.plexcompanion.start()
self.playback_starter.start()
self.playqueue.start()
if utils.settings('enable_alexa') == 'true':
self.alexa.start()