<commit_before>import sys
import traceback
import inspect
import time
import irc.client
import tehbot.plugins as plugins
import tehbot.impl as impl
import tehbot.settings as settings

class Tehbot:
    def __init__(self):
        self.reactor = irc.client.Reactor()
        self.impl = None
        self.reload()
        self.finalize()

    def __getattr__(self, attr):
        return getattr(self.impl, attr)

    def reload(self):
        try:
            reload(settings)
            reload(impl)
            reload(plugins)
            self.newimpl = impl.TehbotImpl(self)
            modules = self.newimpl.gather_modules()
            map(reload, modules)
            self.newimpl.load_plugins(modules)
        except Exception as e:
            Tehbot.print_exc()
            self.newimpl = None
            frm = inspect.trace()[-1]
            mod = inspect.getmodule(frm[0])
            lineno = frm[0].f_lineno
            try:
                modname = mod.__name__
            except:
                modname = "<unknown module>"
            return (modname, lineno, e)

    def finalize(self):
        if self.newimpl is None:
            return

        try:
            self.impl and self.impl.deinit()
        except:
            Tehbot.print_exc()

        try:<commit_msg>core: allow reload with missing modules<commit_after>import sys
import traceback
import inspect
import time
import irc.client
import tehbot.plugins as plugins
import tehbot.impl as impl
import tehbot.settings as settings

class Tehbot:
    def __init__(self):
        self.reactor = irc.client.Reactor()
        self.impl = None
        self.reload()
        self.finalize()

    def __getattr__(self, attr):
        return getattr(self.impl, attr)

    def reload(self):
        try:
            reload(settings)
            reload(impl)
            reload(plugins)
            self.newimpl = impl.TehbotImpl(self)
            modules = self.newimpl.gather_modules()
            for m in modules:
                try:
                    reload(m)
                except ImportError:
                    pass
            self.newimpl.load_plugins(modules)
        except Exception as e:
            Tehbot.print_exc()
            self.newimpl = None
            frm = inspect.trace()[-1]
            mod = inspect.getmodule(frm[0])
            lineno = frm[0].f_lineno
            try:
                modname = mod.__name__
            except:
                modname = "<unknown module>"
            return (modname, lineno, e)

    def finalize(self):
        if self.newimpl is None:
            return

        try:
            self.impl and self.impl.deinit()
        except:
            Tehbot.print_exc()

        try:
{'fraction_non_alphanumeric': 0.08348657594703936, 'fraction_numerical': 0.002206693637366679, 'mean_word_length': 1.5781990521327014, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3054533', 'n_tokens_mistral': 785, 'n_tokens_neox': 752, 'n_words': 189}