<commit_before>import threading
import sublime

try:
    import queue
except ImportError:
    import Queue as queue

if int(sublime.version()) < 3000:
    from sublime_haskell_common import log
else:
    from SublimeHaskell.sublime_haskell_common import log


# Background worker
class Worker(threading.Thread):
    def __init__(self):
        super(Worker, self).__init__()
        self.jobs = queue.Queue()

    def run(self):
        while True:
            name, fn, args, kwargs = self.jobs.get()
            try:
                fn(*args, **kwargs)
            except Exception as e:
                log('worker: job {0} fails with {1}'.format(name, e), log_debug)

    def async(self, name, fn, *args, **kwargs):
        self.jobs.put((name, fn, args, kwargs))

worker = None


def run_async(name, fn, *args, **kwargs):
    global worker
    if not worker:
        worker = Worker()
        worker.start()
    worker.async(name, fn, *args, **kwargs)<commit_msg>Fixed worker: restart if crashed<commit_after>import threading
import sublime

try:
    import queue
except ImportError:
    import Queue as queue

if int(sublime.version()) < 3000:
    from sublime_haskell_common import log, log_debug
else:
    from SublimeHaskell.sublime_haskell_common import log, log_debug


# Background worker
class Worker(threading.Thread):
    def __init__(self):
        super(Worker, self).__init__()
        self.jobs = queue.Queue()

    def run(self):
        while True:
            name, fn, args, kwargs = self.jobs.get()
            try:
                fn(*args, **kwargs)
            except Exception as e:
                log('worker: job {0} fails with {1}'.format(name, e), log_debug)

    def async(self, name, fn, *args, **kwargs):
        self.jobs.put((name, fn, args, kwargs))

worker = None


def run_async(name, fn, *args, **kwargs):
    global worker
    if not worker or not worker.is_alive():
        worker = Worker()
        worker.start()
    worker.async(name, fn, *args, **kwargs)
{'fraction_non_alphanumeric': 0.11488511488511488, 'fraction_numerical': 0.005994005994005994, 'mean_word_length': 2.6220614828209765, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7072089', 'n_tokens_mistral': 650, 'n_tokens_neox': 616, 'n_words': 184}