<commit_before>import sys
import os
import subprocess
import asyncio
from types import ModuleType

try:
    ensure_future = asyncio.ensure_future
except AttributeError:
    ensure_future = getattr(asyncio, 'async')

try:
    from typing import Callable
    hook_type = Callable[[], None]
except ImportError:
    from types import FunctionType
    hook_type = FunctionType

abstract_loop = asyncio.AbstractEventLoop

task = None
reload_attempted = False
reload_hook = None
files = set()


def start(
        loop: abstract_loop = None,
        interval: float = 0.5,
        hook: hook_type = None) -> asyncio.Task:
    """
    Start the reloader.

    Create the task which is watching loaded modules
    and manually added files via ``watch()``
    and reloading the process in case of modification.
    Attach this task to the loop.

    If ``hook`` is provided, it will be called right before
    the application goes to the reload stage.
    """
    if loop is None:
        loop = asyncio.get_event_loop()

    global reload_hook
    if hook is not None:
        reload_hook = hook

    global task
    if not task:
        modify_times = {}
        task = call_periodically(
            loop,
            interval,
            check_and_reload,
            modify_times
        )
    return task


def watch(path: str) -> None:
    """Add any file to the watching list."""
    files.add(path)


def call_periodically(loop: abstract_loop, interval, callback, *args):
    @asyncio.coroutine
    def wrap():
        while True:
            yield from asyncio.sleep(interval, loop=loop)
            yield from callback(*args, loop=loop)
    return ensure_future(wrap(), loop=loop)


@asyncio.coroutine
def check_and_reload(modify_times, loop: abstract_loop):
    if reload_attempted:
        return
    files_changed = yield from loop.run_in_executor(
        None,
        check_all,
        modify_times
    )<commit_msg>Run check_all in custom ThreadPoolExecutor<commit_after>import sys
import os
import subprocess
import asyncio
from concurrent.futures import ThreadPoolExecutor
from types import ModuleType

try:
    ensure_future = asyncio.ensure_future
except AttributeError:
    ensure_future = getattr(asyncio, 'async')

try:
    from typing import Callable
    hook_type = Callable[[], None]
except ImportError:
    from types import FunctionType
    hook_type = FunctionType

abstract_loop = asyncio.AbstractEventLoop

task = None
reload_attempted = False
reload_hook = None
files = set()


def start(
        loop: abstract_loop = None,
        interval: float = 0.5,
        hook: hook_type = None) -> asyncio.Task:
    """
    Start the reloader.

    Create the task which is watching loaded modules
    and manually added files via ``watch()``
    and reloading the process in case of modification.
    Attach this task to the loop.

    If ``hook`` is provided, it will be called right before
    the application goes to the reload stage.
    """
    if loop is None:
        loop = asyncio.get_event_loop()

    global reload_hook
    if hook is not None:
        reload_hook = hook

    global task
    if not task:
        modify_times = {}
        executor = ThreadPoolExecutor(1)
        task = call_periodically(
            loop,
            interval,
            check_and_reload,
            modify_times,
            executor,
        )
    return task


def watch(path: str) -> None:
    """Add any file to the watching list."""
    files.add(path)


def call_periodically(loop: abstract_loop, interval, callback, *args):
    @asyncio.coroutine
    def wrap():
        while True:
            yield from asyncio.sleep(interval, loop=loop)
            yield from callback(*args, loop=loop)
    return ensure_future(wrap(), loop=loop)


@asyncio.coroutine
def check_and_reload(modify_times, executor, loop: abstract_loop):
    if reload_attempted:
        return
    files_changed = yield from loop.run_in_executor(
        executor,
        check_all,
        modify_times
    )
{'fraction_non_alphanumeric': 0.07312203643623659, 'fraction_numerical': 0.0012478163214374844, 'mean_word_length': 2.6469517743403093, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '778495', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1131, 'n_words': 380}