<commit_before>import irc.client
import plugins
import settings
import dynamic
import functools
from Queue import Queue, Empty
from threading import Thread

class Tehbot:
    def __init__(self):
        self.reactor = irc.client.Reactor()
        self.quit_called = False
        self.is_reloading = False
        self.dispatcher = None
        self._init()
        self.queue = Queue(maxsize=0)
        for i in xrange(10):
            worker = Thread(target=self._process)
            worker.start()

    def _init(self):
        if self.dispatcher:
            self.reactor.remove_global_handler("all_events", self.dispatcher.dispatch)
        self.dispatcher = dynamic.Dispatcher(self)
        self.reactor.add_global_handler("all_events", self.dispatcher.dispatch, -10)
        print "pub cmd handlers:", plugins.pub_cmd_handlers
        print "channel handlers:", plugins.channel_handlers

    def _process(self):
        while True:
            try:
                fnc, args = self.queue.get(timeout=1)
                if not self.is_reloading:
                    fnc(*args)
                self.queue.task_done()
            except Empty:
                pass
            if self.quit_called:
                return
            
    def connect(self):
        for c in settings.connections:
            conn = self.reactor.server()
            conn.params = c
            conn.locks = dict()
            self.reconnect(conn)

    def reconnect(self, connection):
        name, host, port, use_ssl, password, bot_password, channels, ops = connection.params
        if use_ssl:
            import ssl
            factory = irc.client.connection.Factory(wrapper=ssl.wrap_socket)
        else:
            factory = irc.client.connection.Factory()
        connection.connect(host, port, settings.bot_name, bot_password, settings.bot_name, settings.bot_name, factory)
        connection.set_rate_limit(4)
        connection.set_keepalive(60)
        
    def reload(self):
        self.is_reloading = True
        res = None
        try:
            reload(settings)
            reload(dynamic)
            plugins.plugins_reload(),
            self._init()
        except Exception as e:
            res = e
        self.is_reloading = False
        return res

    def quit(self, msg="bye-bye"):
        print "quit called"
        self.quit_called = True
        self.reactor.disconnect_all(msg)
        raise SystemExit<commit_msg>change magic value to named constant<commit_after>import irc.client
import plugins
import settings
import dynamic
import functools
from Queue import Queue, Empty
from threading import Thread

nr_worker_threads = 10

class Tehbot:
    def __init__(self):
        self.reactor = irc.client.Reactor()
        self.quit_called = False
        self.is_reloading = False
        self.dispatcher = None
        self._init()
        self.queue = Queue(maxsize=0)
        for i in xrange(nr_worker_threads):
            worker = Thread(target=self._process)
            worker.start()

    def _init(self):
        if self.dispatcher:
            self.reactor.remove_global_handler("all_events", self.dispatcher.dispatch)
        self.dispatcher = dynamic.Dispatcher(self)
        self.reactor.add_global_handler("all_events", self.dispatcher.dispatch, -10)
        print "pub cmd handlers:", plugins.pub_cmd_handlers
        print "channel handlers:", plugins.channel_handlers

    def _process(self):
        while True:
            try:
                fnc, args = self.queue.get(timeout=1)
                if not self.is_reloading:
                    fnc(*args)
                self.queue.task_done()
            except Empty:
                pass
            if self.quit_called:
                return

    def connect(self):
        for c in settings.connections:
            conn = self.reactor.server()
            conn.params = c
            conn.locks = dict()
            self.reconnect(conn)

    def reconnect(self, connection):
        name, host, port, use_ssl, password, bot_password, channels, ops = connection.params
        if use_ssl:
            import ssl
            factory = irc.client.connection.Factory(wrapper=ssl.wrap_socket)
        else:
            factory = irc.client.connection.Factory()
        connection.connect(host, port, settings.bot_name, bot_password, settings.bot_name, settings.bot_name, factory)
        connection.set_rate_limit(4)
        connection.set_keepalive(60)

    def reload(self):
        self.is_reloading = True
        res = None
        try:
            reload(settings)
            reload(dynamic)
            plugins.plugins_reload(),
            self._init()
        except Exception as e:
            res = e
        self.is_reloading = False
        return res

    def quit(self, msg="bye-bye"):
        print "quit called"
        self.quit_called = True
        self.reactor.disconnect_all(msg)
        raise SystemExit
{'fraction_non_alphanumeric': 0.08472165786265745, 'fraction_numerical': 0.0036570499796830555, 'mean_word_length': 1.9373508353221958, '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': '5338125', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1338, 'n_words': 316}