<commit_before>import cherrypy
import FritzDect
import jinja2
import json


class FritzServer(object):

    def __init__(self):
        self.fritz = FritzDect.FritzDect()
        self.env = jinja2.Environment(loader=jinja2.PackageLoader("FritzDect","templates"))
        self.devicelist = self.fritz.getDevices()
        cherrypy.process.plugins.BackgroundTask(60, self.update_device_list)

    @cherrypy.expose
    def index(self):
        page = self.env.get_template("index.html")
        return page.render(devicelist=self.devicelist)

    @cherrypy.expose
    def switch(self, ain):
        try:
            device = next(dev for dev in self.devicelist if dev.ain == ain)
            device.toggle()
        except ValueError:
            pass
        raise cherrypy.HTTPRedirect('/')
<commit_msg>Toggling moved to own thread for faster response<commit_after>import cherrypy
import FritzDect
import jinja2
import json
from threading import Thread


class FritzServer(object):

    def __init__(self):
        self.fritz = FritzDect.FritzDect()
        self.env = jinja2.Environment(loader=jinja2.PackageLoader("FritzDect","templates"))
        self.devicelist = self.fritz.getDevices()
        cherrypy.process.plugins.BackgroundTask(60, self.update_device_list)

    @cherrypy.expose
    def index(self):
        page = self.env.get_template("index.html")
        return page.render(devicelist=self.devicelist)

    @cherrypy.expose
    def switch(self, ain):
        try:
            device = next(dev for dev in self.devicelist if dev.ain == ain)
            thread = Thread(target=device.toggle)
            thread.start()
        except ValueError:
            pass
        raise cherrypy.HTTPRedirect('/')

{'fraction_non_alphanumeric': 0.09959231217239371, 'fraction_numerical': 0.005824111822947, 'mean_word_length': 2.8348214285714284, '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': '4166662', 'n_tokens_mistral': 552, 'n_tokens_neox': 519, 'n_words': 107}