<commit_before>import gevent

from gevent.pywsgi import WSGIServer
from werkzeug.debug import DebuggedApplication

from utils.service import Service
from api.app import app, api
from api.volume import register_resources


class Api(Service):
    def __init__(self, volume_manager, host='', port=5000):
        self._api_server = WSGIServer((host, port), DebuggedApplication(app))
        app.volume_manager = volume_manager
        register_resources(api)

        self._api_loop = None
        self._started = False

    def start(self):
        if self._started:
            return

        self._started = True
        self._api_loop = gevent.spawn(self._api_server.serve_forever)

        return [self._api_loop]

    def stop(self):
        if not self._started:
            return

        self._started = False
        self._api_server.stop()<commit_msg>start/stop uniform responses, now using Connection + util import cleanup<commit_after>import gevent

from flask import Flask
from gevent.pywsgi import WSGIServer
from werkzeug.debug import DebuggedApplication

from utils import Service, Connection


class Api(Service):
    def __init__(self, app: Flask, connection: Connection=Connection('', 5000)):
        self._api_server = WSGIServer(connection, DebuggedApplication(app))

        self._api_loop = None
        self._started = False

    def start(self):
        if self._started:
            return False

        self._started = True
        self._api_loop = gevent.spawn(self._api_server.serve_forever)

        return [self._api_loop]

    def stop(self):
        if not self._started:
            return False

        self._started = False
        self._api_server.stop()

        return True
{'fraction_non_alphanumeric': 0.07701283547257877, 'fraction_numerical': 0.004667444574095682, 'mean_word_length': 2.769230769230769, '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': '4059340', 'n_tokens_mistral': 508, 'n_tokens_neox': 469, 'n_words': 127}