<commit_before># -*- coding: utf-8 *-*
"""
These uwsgi commands are very tightly connected to django deployment
and / or virtualenv.
"""
from commands.python import virtualenv
from commands import scp
from fabric.context_managers import settings, cd
from fabric.contrib.files import exists
from fabric.operations import run
import logging

def is_running(deployment):
    if not exists("%s/uwsgi.pid" % deployment.get_config_value('uwsgi/workdir')):
        return False
    with settings(warn_only=True):
        uwsgi_running = run("kill -s 0 `cat %(uwsgi)s/uwsgi.pid`" % {
            "uwsgi": deployment.get_config_value('uwsgi/workdir')
        })
        
        return not uwsgi_running.failed

def restart(deployment):
    #we need to check whether uwsgi is started in emperor mode or not.
    emperor = deployment.get_config_value('uwsgi/emperor', True)
    vassals_dir = deployment.get_config_value('uwsgi/vassals_dir')
    #then, check if the master instance of uwsgi exists. If not, there's no
    #need to restart, as it will pick up vassal automatically.
        
    if emperor:
        with cd(vassals_dir):
            if not is_running(deployment):
                #start uwsgi, as it will pick up the vassal from vassal's dir.
                start(deployment)
                return
            if exists(deployment.vassal[0]):
                run("touch %s" % deployment.vassal[0])
            else:
                scp(
                    deployment.get_config_value('uwsgi/launcher'),
                    vassals_dir + "/" + deployment.vassal[0]
                )
    else:
        stop(deployment)
        start(deployment)

def start(deployment):
    #we need to check whether uwsgi is started in emperor mode or not.
    emperor = deployment.get_config_value('uwsgi/emperor', True)<commit_msg>gracefully kill uwsgi worker when using emperor mode<commit_after># -*- coding: utf-8 *-*
"""
These uwsgi commands are very tightly connected to django deployment
and / or virtualenv.
"""
from commands.python import virtualenv
from commands import scp
from fabric.context_managers import settings, cd
from fabric.contrib.files import exists
from fabric.operations import run
import logging

def is_running(deployment):
    if not exists("%s/uwsgi.pid" % deployment.get_config_value('uwsgi/workdir')):
        return False
    with settings(warn_only=True):
        uwsgi_running = run("kill -s 0 `cat %(uwsgi)s/uwsgi.pid`" % {
            "uwsgi": deployment.get_config_value('uwsgi/workdir')
        })
        
        return not uwsgi_running.failed

def restart(deployment):
    #we need to check whether uwsgi is started in emperor mode or not.
    emperor = deployment.get_config_value('uwsgi/emperor', True)
    vassals_dir = deployment.get_config_value('uwsgi/vassals_dir')
    #then, check if the master instance of uwsgi exists. If not, there's no
    #need to restart, as it will pick up vassal automatically.
        
    if emperor:
        with cd(vassals_dir):
            if not is_running(deployment):
                #start uwsgi, as it will pick up the vassal from vassal's dir.
                start(deployment)
                return
            if exists(deployment.vassal[0]):
                run("kill -HUP `cat %s/uwsgi.pid`" %
                    deployment.get_config_value('uwsgi/workdir')
                    )
            else:
                scp(
                    deployment.get_config_value('uwsgi/launcher'),
                    vassals_dir + "/" + deployment.vassal[0]
                )
    else:
        stop(deployment)
        start(deployment)

def start(deployment):
    #we need to check whether uwsgi is started in emperor mode or not.
    emperor = deployment.get_config_value('uwsgi/emperor', True)
{'fraction_non_alphanumeric': 0.09028146574614976, 'fraction_numerical': 0.002389803505045141, 'mean_word_length': 2.471889400921659, 'pattern_counts': {'":': 2, '<': 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': '339429', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1109, 'n_words': 318}