<commit_before>from __future__ import print_function
from __future__ import absolute_import
# myapp.mycustomapplication
from builtins import str
from gunicorn.app.base import Application
from gunicorn import util
import multiprocessing
from psiturk.psiturk_config import PsiturkConfig
import os
import hashlib
from gevent import monkey
monkey.patch_all()

config = PsiturkConfig()
config.load_config()


class ExperimentServer(Application):
    '''
    Custom Gunicorn Server Application that serves up the Experiment application
    '''

    def __init__(self):
        '''__init__ method
        Load the base config and assign some core attributes.
        '''
        self.load_user_config()
        self.usage = None
        self.callable = None
        self.options = self.user_options
        self.prog = None
        self.do_load_config()
        print("Now serving on", "http://" + self.options["bind"])

    def init(self, *args):
        '''init method
        Takes our custom options from self.options and creates a config
        dict which specifies custom settings.
        '''
        cfg = {}
        for k, v in list(self.options.items()):
            if k.lower() in self.cfg.settings and v is not None:
                cfg[k.lower()] = v
        return cfg

    def load(self):
        '''load method
        Imports our application and returns it to be run.
        '''
        return util.import_app("psiturk.experiment:app")

    def load_user_config(self):
        # config calls these threads to avoid confusing with workers
        workers = config.get("Server Parameters", "threads")
        if workers == "auto":
            workers = str(multiprocessing.cpu_count() * 2 + 1)

        self.loglevels = ["debug", "info", "warning", "error", "critical"]

        def on_exit(server):
            ''' 
            this is hooked so that it can be called when 
            the server is shut down via CTRL+C. Otherwise
            there is no notification to the user that the server
            has shut down until they hit `enter` and see that 
            the cmdloop prompt suddenly says "server off"
            '''
            print('Caught ^C, experiment server has shut down.')
            print('Press `enter` to continue.')
<commit_msg>do not allow scheduler if more than one thread<commit_after>from __future__ import print_function
from __future__ import absolute_import
# myapp.mycustomapplication
from builtins import str
from gunicorn.app.base import Application
from gunicorn import util
import multiprocessing
from psiturk.psiturk_config import PsiturkConfig
import os
import hashlib
from gevent import monkey
monkey.patch_all()

config = PsiturkConfig()
config.load_config()


class ExperimentServer(Application):
    '''
    Custom Gunicorn Server Application that serves up the Experiment application
    '''

    def __init__(self):
        '''__init__ method
        Load the base config and assign some core attributes.
        '''
        self.load_user_config()
        self.usage = None
        self.callable = None
        self.options = self.user_options
        self.prog = None
        self.do_load_config()
        print("Now serving on", "http://" + self.options["bind"])

    def init(self, *args):
        '''init method
        Takes our custom options from self.options and creates a config
        dict which specifies custom settings.
        '''
        cfg = {}
        for k, v in list(self.options.items()):
            if k.lower() in self.cfg.settings and v is not None:
                cfg[k.lower()] = v
        return cfg

    def load(self):
        '''load method
        Imports our application and returns it to be run.
        '''
        return util.import_app("psiturk.experiment:app")

    def load_user_config(self):
        # config calls these threads to avoid confusing with workers
        workers = config.get("Server Parameters", "threads")
        if workers == "auto":
            workers = str(multiprocessing.cpu_count() * 2 + 1)

        if int(workers) > 1 and os.getenv('PSITURK_DO_SCHEDULER', False):
            raise Exception((
                'Scheduler is not thread-safe, '
                'but {} gunicorn workers requested! Refusing to start!'
                ).format(workers)
            )

        self.loglevels = ["debug", "info", "warning", "error", "critical"]

        def on_exit(server):
            '''
            this is hooked so that it can be called when
            the server is shut down via CTRL+C. Otherwise
            there is no notification to the user that the server
            has shut down until they hit `enter` and see that
            the cmdloop prompt suddenly says "server off"
            '''
            print('Caught ^C, experiment server has shut down.')
            print('Press `enter` to continue.')

{'fraction_non_alphanumeric': 0.08522492777548493, 'fraction_numerical': 0.0010317787866281469, 'mean_word_length': 2.31986301369863, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 4, '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': '491694', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1250, 'n_words': 466}