<commit_before>import logging
import sys

from pykka.actor import ThreadingActor

from mopidy import settings
from mopidy.utils import network
from mopidy.frontends.mpd.dispatcher import MpdDispatcher
from mopidy.frontends.mpd.protocol import ENCODING, VERSION, LINE_TERMINATOR

logger = logging.getLogger('mopidy.frontends.mpd')

class MpdFrontend(ThreadingActor):
    """
    The MPD frontend.

    **Dependencies:**

    - None

    **Settings:**

    - :attr:`mopidy.settings.MPD_SERVER_HOSTNAME`
    - :attr:`mopidy.settings.MPD_SERVER_PORT`
    - :attr:`mopidy.settings.MPD_SERVER_PASSWORD`
    """

    def __init__(self):
        hostname = network.format_hostname(settings.MPD_SERVER_HOSTNAME)
        port = settings.MPD_SERVER_PORT

        try:
            network.Listener(hostname, port, MpdSession)
        except IOError, e:
            logger.error(u'MPD server startup failed: %s', e)
            sys.exit(1)

        logger.info(u'MPD server running at [%s]:%s', hostname, port)

    def on_receive(self, message):
        pass # Ignore state info that is sent to frontend.


class MpdSession(network.LineProtocol):
    """
    The MPD client session. Keeps track of a single client session. Any
    requests from the client is passed on to the MPD request dispatcher.
    """

    terminator = LINE_TERMINATOR
    encoding = ENCODING

    def __init__(self, sock, addr):
        super(MpdSession, self).__init__(sock, addr)
        self.dispatcher = MpdDispatcher(self)

    def on_start(self):
        self.send_lines([u'OK MPD %s' % VERSION])

    def on_line_recieved(self, line):
        self.send_lines(self.dispatcher.handle_request(line))

    def close(self):<commit_msg>Stop all sesions when mpd frontend is asked to stop<commit_after>import logging
import sys

from pykka.actor import ThreadingActor

from mopidy import settings
from mopidy.utils import network
from mopidy.utils.process import stop_actors_by_class
from mopidy.frontends.mpd.dispatcher import MpdDispatcher
from mopidy.frontends.mpd.protocol import ENCODING, VERSION, LINE_TERMINATOR

logger = logging.getLogger('mopidy.frontends.mpd')

class MpdFrontend(ThreadingActor):
    """
    The MPD frontend.

    **Dependencies:**

    - None

    **Settings:**

    - :attr:`mopidy.settings.MPD_SERVER_HOSTNAME`
    - :attr:`mopidy.settings.MPD_SERVER_PORT`
    - :attr:`mopidy.settings.MPD_SERVER_PASSWORD`
    """

    def __init__(self):
        hostname = network.format_hostname(settings.MPD_SERVER_HOSTNAME)
        port = settings.MPD_SERVER_PORT

        try:
            network.Listener(hostname, port, MpdSession)
        except IOError, e:
            logger.error(u'MPD server startup failed: %s', e)
            sys.exit(1)

        logger.info(u'MPD server running at [%s]:%s', hostname, port)

    def on_receive(self, message):
        pass # Ignore state info that is sent to frontend.

    def on_stop(self):
        stop_actors_by_class(MpdSession)


class MpdSession(network.LineProtocol):
    """
    The MPD client session. Keeps track of a single client session. Any
    requests from the client is passed on to the MPD request dispatcher.
    """

    terminator = LINE_TERMINATOR
    encoding = ENCODING

    def __init__(self, sock, addr):
        super(MpdSession, self).__init__(sock, addr)
        self.dispatcher = MpdDispatcher(self)

    def on_start(self):
        self.send_lines([u'OK MPD %s' % VERSION])

    def on_line_recieved(self, line):
        self.send_lines(self.dispatcher.handle_request(line))

    def close(self):
{'fraction_non_alphanumeric': 0.09592123769338959, 'fraction_numerical': 0.0005625879043600563, 'mean_word_length': 3.243436754176611, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4717256', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1122, 'n_words': 273}