<commit_before># from threading import Timer, Thread

from .compat import Queue
# from .context import Context

# Based on https://github.com/petkaantonov/bluebird/blob/master/src/async.js


class Scheduler(object):

    def call(self, fn):
        # thread = Thread(target=fn)
        # thread = Timer(0.001, fn)
        # fn = thread.start
        try:
            # c = Context.peek_context()
            # if not c:
            fn()
            # else:
            #     c.on_exit(fn)
        except:
            pass
        # thread = Thread(target=fn)
        # thread = Timer(0.001, fn)
        # thread.start()


def get_default_scheduler():
    return Scheduler()


# https://docs.python.org/2/library/queue.html#Queue.Queue
LATE_QUEUE_CAPACITY = 0  # The queue size is infinite
NORMAL_QUEUE_CAPACITY = 0  # The queue size is infinite


class Async(object):

    def __init__(self, schedule=None):
        self.is_tick_used = False
        self.late_queue = Queue(LATE_QUEUE_CAPACITY)
        self.normal_queue = Queue(NORMAL_QUEUE_CAPACITY)
        self.have_drained_queues = False
        self.trampoline_enabled = True
        self.schedule = schedule or get_default_scheduler()

    def enable_trampoline(self):
        self.trampoline_enabled = True

    def disable_trampoline(self):
        self.trampoline_enabled = False

    def have_items_queued(self):
        return self.is_tick_used or self.have_drained_queues

    def _async_invoke_later(self, fn, context):
        self.late_queue.put(fn)
        self.queue_tick(context)

    def _async_invoke(self, fn, context):<commit_msg>Improved async<commit_after># from threading import Timer, Thread

from .compat import Queue
# from .context import Context

# Based on https://github.com/petkaantonov/bluebird/blob/master/src/async.js


class Scheduler(object):

    def call(self, fn):
        # thread = Thread(target=fn)
        # thread = Timer(0.01, fn)
        # fn = thread.start
        # try:
            # c = Context.peek_context()
            # if not c:
        fn()
            # else:
            #     c.on_exit(fn)
        # except:
        #     pass
        # thread = Thread(target=fn)
        # thread = Timer(0.001, fn)
        # thread.start()


def get_default_scheduler():
    return Scheduler()


# https://docs.python.org/2/library/queue.html#Queue.Queue
LATE_QUEUE_CAPACITY = 0  # The queue size is infinite
NORMAL_QUEUE_CAPACITY = 0  # The queue size is infinite


class Async(object):

    def __init__(self, schedule=None):
        self.is_tick_used = False
        self.late_queue = Queue(LATE_QUEUE_CAPACITY)
        self.normal_queue = Queue(NORMAL_QUEUE_CAPACITY)
        self.have_drained_queues = False
        self.trampoline_enabled = False
        self.schedule = schedule or get_default_scheduler()

    def enable_trampoline(self):
        self.trampoline_enabled = True

    def disable_trampoline(self):
        self.trampoline_enabled = False

    def have_items_queued(self):
        return self.is_tick_used or self.have_drained_queues

    def _async_invoke_later(self, fn, context):
        self.late_queue.put(fn)
        self.queue_tick(context)

    def _async_invoke(self, fn, context):
{'fraction_non_alphanumeric': 0.09566843253349953, 'fraction_numerical': 0.006544094733561857, 'mean_word_length': 2.5081967213114753, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '2801278', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1006, 'n_words': 216}