<commit_before>from .common import KnowledgeDeployer
import logging
import os
import shutil
import subprocess

logger = logging.getLogger()


class uWSGIDeployer(KnowledgeDeployer):

    _registry_keys = ['uwsgi']

    COMMAND = "uwsgi {protocol} --plugin python --wsgi-file {{path}} --callable app --master --processes {{processes}} --threads {{threads}}"

    def run(self):
        if not self.app.check_thread_support():
            raise RuntimeError("Database configuration is not suitable for deployment (not thread-safe).")

        tmp_dir = self.write_temp_files()

        options = {
            'socket': '{}:{}'.format(self.host, self.port),
            'processes': self.workers,
            'threads': 2,
            'timeout': self.timeout,
            'path': os.path.join(tmp_dir, 'server.py'),
            'cert': self.app.config['SSL_CERT']['cert'],
            'key': self.app.config['SSL_CERT']['key']
        }

        if self.app.config['DEPLOY_HTTPS']:
            self.COMMAND = self.COMMAND.format(protocol="--https {socket},{cert},{key}")
        else:
            self.COMMAND = self.COMMAND.format(protocol="--http {socket}")

        try:
            cmd = "cd {};".format(tmp_dir) + self.COMMAND.format(**options)
            logger.info("Starting server with command: %s", " ".join(cmd))
            subprocess.check_output(cmd, shell=True)
        finally:
            shutil.rmtree(tmp_dir)<commit_msg>Clean up the code in uwsgi<commit_after>from .common import KnowledgeDeployer
import logging
import os
import shutil
import subprocess

logger = logging.getLogger()


class uWSGIDeployer(KnowledgeDeployer):

    _registry_keys = ['uwsgi']

    COMMAND = (
        'uwsgi {protocol} --plugin python --wsgi-file {{path}} --callable app '
        '--master --processes {{processes}} --threads {{threads}}'
    )

    def run(self):
        if not self.app.check_thread_support():
            raise RuntimeError('Database configuration is not suitable '
                               'for deployment (not thread-safe).')

        tmp_dir = self.write_temp_files()

        options = {
            'socket': f'{self.host}:{self.port}',
            'processes': self.workers,
            'threads': 2,
            'timeout': self.timeout,
            'path': os.path.join(tmp_dir, 'server.py'),
            'cert': self.app.config['SSL_CERT']['cert'],
            'key': self.app.config['SSL_CERT']['key']
        }

        if self.app.config['DEPLOY_HTTPS']:
            protocol = '--https {socket},{cert},{key}'
        else:
            protocol = '--http {socket}'
        self.COMMAND = self.COMMAND.format(protocol=protocol)

        try:
            cmd = f'cd {tmp_dir};' + self.COMMAND.format(**options)
            logger.info('Starting server with command: %s', ' '.join(cmd))
            subprocess.check_output(cmd, shell=True)
        finally:
            shutil.rmtree(tmp_dir)
{'fraction_non_alphanumeric': 0.14685792349726776, 'fraction_numerical': 0.0006830601092896175, 'mean_word_length': 2.335990888382688, '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': '1667381', 'n_tokens_mistral': 881, 'n_tokens_neox': 863, 'n_words': 185}