<commit_before>import praw
import os
import puni
import datetime
import urllib.parse
import psycopg2
import time
import nltk
import threading
from modules import filters


class CreateThread(threading.Thread):
    def __init__(self, thread_id, name, method, r):
        threading.Thread.__init__(self)
        self.threadID = thread_id
        self.name = name
        self.method = method
        self.r = r

    def run(self):
        print("Starting " + self.name)
        methodToRun = self.method(self.r)
        print("Exiting " + self.name)


class BotMod:

    """Main class for BotMod"""

    def __init__(self, s, devmode=False, use_database=False, use_commands=True, search_reposts=True):

        print("Initializing BotMod...")
        self.s = s
        self.devmode = devmode
        self.use_database = use_database
        self.listening = False
        self.channel = None
        self.subreddit = None
        self.refreshing = True
        self.already_done_reposts = []

        print("Connecting to reddit...")

        app_uri = 'https://127.0.0.1:65010/authorize_callback'
        self.r = praw.Reddit(user_agent='windows:ELI5Mod:v3 (by /u/santi871)')
        self.r.set_oauth_app_info(os.environ['REDDIT_APP_ID'], os.environ['REDDIT_APP_SECRET'], app_uri)
        self.r.refresh_access_information(os.environ['REDDIT_REFRESH_TOKEN'])
        self.r.config.api_request_delay = 1
<commit_msg>catch exceptions in a thread and restart thread<commit_after>import praw
import os
import puni
import datetime
import urllib.parse
import psycopg2
import time
import nltk
import threading
from modules import filters


class CreateThread(threading.Thread):
    def __init__(self, thread_id, name, method, r):
        threading.Thread.__init__(self)
        self.threadID = thread_id
        self.name = name
        self.method = method
        self.r = r

    def run(self):

        while True:
            try:
                print("Starting " + self.name)
                methodToRun = self.method(self.r)
                print("Exiting " + self.name)
            except Exception as e:
                print("Failure in thread '%s', exception: %s" % (self.name, e))
                time.sleep(1)


class BotMod:

    """Main class for BotMod"""

    def __init__(self, s, devmode=False, use_database=False, use_commands=True, search_reposts=True):

        print("Initializing BotMod...")
        self.s = s
        self.devmode = devmode
        self.use_database = use_database
        self.listening = False
        self.channel = None
        self.subreddit = None
        self.refreshing = True
        self.already_done_reposts = []

        print("Connecting to reddit...")

        app_uri = 'https://127.0.0.1:65010/authorize_callback'
        self.r = praw.Reddit(user_agent='windows:ELI5Mod:v3 (by /u/santi871)')
        self.r.set_oauth_app_info(os.environ['REDDIT_APP_ID'], os.environ['REDDIT_APP_SECRET'], app_uri)
        self.r.refresh_access_information(os.environ['REDDIT_REFRESH_TOKEN'])
        self.r.config.api_request_delay = 1

{'fraction_non_alphanumeric': 0.10582872028655162, 'fraction_numerical': 0.012048192771084338, 'mean_word_length': 2.5971896955503513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '162749', 'n_tokens_mistral': 1003, 'n_tokens_neox': 976, 'n_words': 207}