<commit_before>import signal
import time

import typing as tp

end = False


def __sighandler(a, b):
    global end
    end = True


def hang_until_sig(extra_signals: tp.Optional[tp.List[int]] = None,
                   end_on_keyboard_interrupt: bool = True) -> None:
    """
    Will hang until this process receives SIGTERM or SIGINT.
    If you pass extra signal IDs (signal.SIG*) with extra_signals,
    then also on those signals this call will release.

    :param extra_signals: a list of extra signals to listen to
    :param end_on_keyboard_interrupt: whether to consider receiving a KeyboardInterrupt as
        a signal to finish
    global end
    """
    extra_signals = extra_signals or []

    signal.signal(signal.SIGTERM, __sighandler)
    signal.signal(signal.SIGINT, __sighandler)
    for s in extra_signals:
        signal.signal(s, __sighandler)

    while not end:
        try:
            time.sleep(0.5)
        except KeyboardInterrupt:
            if end_on_keyboard_interrupt:
                end = True

    end = False  # reset for next use<commit_msg>test hang_until_sig<commit_after>import signal
import time

import typing as tp

end = False


def __sighandler(a, b):
    global end
    end = True


def hang_until_sig(extra_signals: tp.Optional[tp.List[int]] = None,
                   end_on_keyboard_interrupt: bool = True) -> None:
    """
    Will hang until this process receives SIGTERM or SIGINT.
    If you pass extra signal IDs (signal.SIG*) with extra_signals,
    then also on those signals this call will release.

    :param extra_signals: a list of extra signals to listen to
    :param end_on_keyboard_interrupt: whether to consider receiving a KeyboardInterrupt as
        a signal to finish
    """
    global end
    extra_signals = extra_signals or []

    signal.signal(signal.SIGTERM, __sighandler)
    signal.signal(signal.SIGINT, __sighandler)
    for s in extra_signals:
        signal.signal(s, __sighandler)

    while not end:
        try:
            time.sleep(0.5)
        except KeyboardInterrupt:
            if end_on_keyboard_interrupt:
                end = True

    end = False  # reset for next use
{'fraction_non_alphanumeric': 0.06543778801843318, 'fraction_numerical': 0.0018433179723502304, 'mean_word_length': 2.6426174496644297, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6573801', 'n_tokens_mistral': 666, 'n_tokens_neox': 651, 'n_words': 214}