<commit_before>#! /usr/bin/python3

# Imports

import subprocess
from serverbasics import OperationFailedError
import sys
from threading import Thread
from queue import Queue, Empty

# Setup code

def enqueue_output(out, queue):
    for line in iter(out.readline, b''):
        queue.put(line)
    out.close()

# Server start code.

class Server():
    """Provides the interface for managing a MCServer server."""

    def __init__(self, filename):
        self.filename = filename
        self.started = 0 # The server is not started quite yet.

    def start(self):
        """Starts the server."""
        if self.started == 1:
            raise OperationFailedError({"operation":"start", "cause":"alreadystarted", "details":None})
        else:
            self.serverprocess = subprocess.Popen([self.filename], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
            self.q = Queue()
            self.t = Thread(target=enqueue_output, args=(self.serverprocess.stdout, self.q))
            self.t.daemon = True
            self.t.start()
            self.started = 1
            return		

    def stop(self):
        """Stops the server."""
        if self.started == 0:
            return
        else:
            output = self.serverprocess.communicate(input=bytes('stop\n', "UTF-8"))[0]
            if self.serverprocess.poll() != 0:
                raise OperationFailedError({"operation":"stop", "cause":"badexit", "details":None})
            self.started = 0

    def runcommand(self, args):
        """Runs the command 'args'."""
        if self.started == 0:<commit_msg>Fixed inconsistency<commit_after>#! /usr/bin/python3

# Imports

import subprocess
from serverbasics import OperationFailedError
import sys
from threading import Thread
from queue import Queue, Empty

# Setup code

def enqueue_output(out, queue):
    for line in iter(out.readline, b''):
        queue.put(line)
    out.close()

# Server start code.

class Server():
    """Provides the interface for managing a MCServer server."""

    def __init__(self, filename):
        self.filename = filename
        self.started = 0 # The server is not started quite yet.

    def start(self):
        """Starts the server."""
        if self.started == 1:
            raise OperationFailedError({"operation":"start", "cause":"alreadystarted", "details":None})
        else:
            self.serverprocess = subprocess.Popen([self.filename], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
            self.q = Queue()
            self.t = Thread(target=enqueue_output, args=(self.serverprocess.stdout, self.q))
            self.t.daemon = True
            self.t.start()
            self.started = 1
            return		

    def stop(self):
        """Stops the server."""
        if self.started == 0:
            raise OperationFailedError({"operation":"stop", "cause":"notstarted", "details":None})
        else:
            output = self.serverprocess.communicate(input=bytes('stop\n', "UTF-8"))[0]
            if self.serverprocess.poll() != 0:
                raise OperationFailedError({"operation":"stop", "cause":"badexit", "details":None})
            self.started = 0

    def runcommand(self, args):
        """Runs the command 'args'."""
        if self.started == 0:
{'fraction_non_alphanumeric': 0.12892512077294685, 'fraction_numerical': 0.006038647342995169, 'mean_word_length': 2.5433155080213905, 'pattern_counts': {'":': 15, '<': 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': '3263610', 'n_tokens_mistral': 980, 'n_tokens_neox': 927, 'n_words': 245}