Split BaseProcess snd CoreProcess into two files
This commit is contained in:
parent
ce878ca797
commit
aede9762f8
@ -10,7 +10,7 @@ sys.path.insert(0,
|
||||
os.path.abspath(os.path.join(os.path.dirname(__file__), '../')))
|
||||
|
||||
from mopidy import get_version, settings, SettingsError
|
||||
from mopidy.process import CoreProcess
|
||||
from mopidy.core import CoreProcess
|
||||
from mopidy.utils import get_class
|
||||
from mopidy.utils.path import get_or_create_folder
|
||||
from mopidy.utils.settings import list_settings_optparse_callback
|
||||
|
||||
@ -4,7 +4,7 @@ import multiprocessing
|
||||
from spotify import Link, SpotifyError
|
||||
|
||||
from mopidy.backends.base import BasePlaybackController
|
||||
from mopidy.process import pickle_connection
|
||||
from mopidy.utils.process import pickle_connection
|
||||
|
||||
logger = logging.getLogger('mopidy.backends.libspotify.playback')
|
||||
|
||||
|
||||
@ -1,42 +1,9 @@
|
||||
import logging
|
||||
import multiprocessing
|
||||
from multiprocessing.reduction import reduce_connection
|
||||
import pickle
|
||||
import sys
|
||||
|
||||
from mopidy import SettingsError
|
||||
|
||||
logger = logging.getLogger('mopidy.process')
|
||||
|
||||
def pickle_connection(connection):
|
||||
return pickle.dumps(reduce_connection(connection))
|
||||
|
||||
def unpickle_connection(pickled_connection):
|
||||
# From http://stackoverflow.com/questions/1446004
|
||||
(func, args) = pickle.loads(pickled_connection)
|
||||
return func(*args)
|
||||
|
||||
|
||||
class BaseProcess(multiprocessing.Process):
|
||||
def run(self):
|
||||
try:
|
||||
self.run_inside_try()
|
||||
except KeyboardInterrupt:
|
||||
logger.info(u'Interrupted by user')
|
||||
sys.exit(0)
|
||||
except SettingsError as e:
|
||||
logger.error(e.message)
|
||||
sys.exit(1)
|
||||
except ImportError as e:
|
||||
logger.error(e)
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
raise e
|
||||
|
||||
def run_inside_try(self):
|
||||
raise NotImplementedError
|
||||
from mopidy.utils.process import BaseProcess, unpickle_connection
|
||||
|
||||
logger = logging.getLogger('mopidy.core')
|
||||
|
||||
class CoreProcess(BaseProcess):
|
||||
def __init__(self, core_queue, output_class, backend_class, frontend):
|
||||
@ -3,8 +3,8 @@ import logging
|
||||
import multiprocessing
|
||||
|
||||
from mopidy.frontends.mpd.protocol import ENCODING, LINE_TERMINATOR, VERSION
|
||||
from mopidy.process import pickle_connection
|
||||
from mopidy.utils import indent
|
||||
from mopidy.utils.process import pickle_connection
|
||||
|
||||
logger = logging.getLogger('mopidy.frontends.mpd.session')
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import multiprocessing
|
||||
|
||||
from mopidy.mixers import BaseMixer
|
||||
from mopidy.process import pickle_connection
|
||||
from mopidy.utils.process import pickle_connection
|
||||
|
||||
class GStreamerSoftwareMixer(BaseMixer):
|
||||
"""Mixer which uses GStreamer to control volume in software."""
|
||||
|
||||
@ -3,9 +3,9 @@ from serial import Serial
|
||||
from multiprocessing import Pipe
|
||||
|
||||
from mopidy.mixers import BaseMixer
|
||||
from mopidy.process import BaseProcess
|
||||
from mopidy.settings import (MIXER_EXT_PORT, MIXER_EXT_SOURCE,
|
||||
MIXER_EXT_SPEAKERS_A, MIXER_EXT_SPEAKERS_B)
|
||||
from mopidy.utils.process import BaseProcess
|
||||
|
||||
logger = logging.getLogger('mopidy.mixers.nad')
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ import gst
|
||||
import logging
|
||||
import threading
|
||||
|
||||
from mopidy.process import BaseProcess, unpickle_connection
|
||||
from mopidy.utils.process import BaseProcess, unpickle_connection
|
||||
|
||||
logger = logging.getLogger('mopidy.outputs.gstreamer')
|
||||
|
||||
|
||||
38
mopidy/utils/process.py
Normal file
38
mopidy/utils/process.py
Normal file
@ -0,0 +1,38 @@
|
||||
import logging
|
||||
import multiprocessing
|
||||
from multiprocessing.reduction import reduce_connection
|
||||
import pickle
|
||||
import sys
|
||||
|
||||
from mopidy import SettingsError
|
||||
|
||||
logger = logging.getLogger('mopidy.utils.process')
|
||||
|
||||
def pickle_connection(connection):
|
||||
return pickle.dumps(reduce_connection(connection))
|
||||
|
||||
def unpickle_connection(pickled_connection):
|
||||
# From http://stackoverflow.com/questions/1446004
|
||||
(func, args) = pickle.loads(pickled_connection)
|
||||
return func(*args)
|
||||
|
||||
|
||||
class BaseProcess(multiprocessing.Process):
|
||||
def run(self):
|
||||
try:
|
||||
self.run_inside_try()
|
||||
except KeyboardInterrupt:
|
||||
logger.info(u'Interrupted by user')
|
||||
sys.exit(0)
|
||||
except SettingsError as e:
|
||||
logger.error(e.message)
|
||||
sys.exit(1)
|
||||
except ImportError as e:
|
||||
logger.error(e)
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
raise e
|
||||
|
||||
def run_inside_try(self):
|
||||
raise NotImplementedError
|
||||
Loading…
Reference in New Issue
Block a user