<commit_before>"""Create and manage the CherryPy application engine."""

import cgi
import os
import signal
import sys
import threading
import time

import cherrypy
from cherrypy import _cprequest

# Use a flag to indicate the state of the application engine.
STOPPED = 0
STARTING = None
STARTED = 1


def fileattr(m):
    if hasattr(m, "__loader__"):
        if hasattr(m.__loader__, "archive"):
            return m.__loader__.archive
    return getattr(m, "__file__", None)


try:
    if hasattr(signal, "SIGHUP"):
        def SIGHUP(signum=None, frame=None):
            cherrypy.engine.reexec()
        signal.signal(signal.SIGHUP, SIGHUP)

    if hasattr(signal, "SIGTERM"):
        def SIGTERM(signum=None, frame=None):
            cherrypy.server.stop()
            cherrypy.engine.stop()
        signal.signal(signal.SIGTERM, SIGTERM)
except ValueError, _signal_exc:
    if _signal_exc.args[0] != "signal only works in main thread":
        raise


class Engine(object):
    """The application engine, which exposes a request interface to (HTTP) servers."""
    
    request_class = _cprequest.Request
    response_class = _cprequest.Response
    
    def __init__(self):
        self.state = STOPPED
        
        # Startup/shutdown hooks
        self.on_start_engine_list = []
        self.on_stop_engine_list = []
        self.on_start_thread_list = []
        self.on_stop_thread_list = []
        self.seen_threads = {}
        
        self.servings = []
        
        self.mtimes = {}
        self.reload_files = []
    
    def start(self, blocking=True):
        """Start the application engine."""
        self.state = STARTING
        
        conf = cherrypy.config.get
        
        # Output config options to log
        if conf("log_config", True):
            cherrypy.config.log_config()
        
        for func in self.on_start_engine_list:
            func()
        
        self.state = STARTED
        
        freq = float(cherrypy.config.get('deadlock_poll_freq', 60))
        if freq > 0:
            self.monitor_thread = threading.Timer(freq, self.monitor)
            self.monitor_thread.start()<commit_msg>Engine.monitor_thread defaults to None now.<commit_after>"""Create and manage the CherryPy application engine."""

import cgi
import os
import signal
import sys
import threading
import time

import cherrypy
from cherrypy import _cprequest

# Use a flag to indicate the state of the application engine.
STOPPED = 0
STARTING = None
STARTED = 1


def fileattr(m):
    if hasattr(m, "__loader__"):
        if hasattr(m.__loader__, "archive"):
            return m.__loader__.archive
    return getattr(m, "__file__", None)


try:
    if hasattr(signal, "SIGHUP"):
        def SIGHUP(signum=None, frame=None):
            cherrypy.engine.reexec()
        signal.signal(signal.SIGHUP, SIGHUP)

    if hasattr(signal, "SIGTERM"):
        def SIGTERM(signum=None, frame=None):
            cherrypy.server.stop()
            cherrypy.engine.stop()
        signal.signal(signal.SIGTERM, SIGTERM)
except ValueError, _signal_exc:
    if _signal_exc.args[0] != "signal only works in main thread":
        raise


class Engine(object):
    """The application engine, which exposes a request interface to (HTTP) servers."""
    
    request_class = _cprequest.Request
    response_class = _cprequest.Response
    
    def __init__(self):
        self.state = STOPPED
        
        # Startup/shutdown hooks
        self.on_start_engine_list = []
        self.on_stop_engine_list = []
        self.on_start_thread_list = []
        self.on_stop_thread_list = []
        self.seen_threads = {}
        
        self.servings = []
        
        self.mtimes = {}
        self.reload_files = []
        
        self.monitor_thread = None
    
    def start(self, blocking=True):
        """Start the application engine."""
        self.state = STARTING
        
        conf = cherrypy.config.get
        
        # Output config options to log
        if conf("log_config", True):
            cherrypy.config.log_config()
        
        for func in self.on_start_engine_list:
            func()
        
        self.state = STARTED
        
        freq = float(cherrypy.config.get('deadlock_poll_freq', 60))
        if freq > 0:
            self.monitor_thread = threading.Timer(freq, self.monitor)
            self.monitor_thread.start()
{'fraction_non_alphanumeric': 0.09625912408759124, 'fraction_numerical': 0.002737226277372263, 'mean_word_length': 2.2337758112094397, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, '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': '1266104', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1297, 'n_words': 317}