<commit_before>import sys
import pickle
from threading import Thread
from Queue import Queue, Empty


# point is to make improbably that would ever happen to appear inside a pickled image and be mistaken
end_of_message_message = ("---EndOfMessage---"*10) + "\n"   

def send_to_stream(stream, msg): 
    """
    Pickle & send to stdout a message.
    Used primarily to communicate back-and-forth with a separately launched ztv process.
    """
    if isinstance(msg, str):
        msg = (msg,)
    pkl = pickle.dumps(msg)
    stream.write(pkl + '\n' + end_of_message_message)
    stream.flush()

class UnexpectedEndOfStream(Exception): pass

class StreamListenerTimeOut(Exception): pass

def _accumulate_to_queue(stream, queue):
    while True:
        line = stream.readline()
        if line:
            queue.put(line)
        else:
# TODO: rather than return, should really raise the Error, but then code elsewhere needs to be catching for it
#             raise UnexpectedEndOfStream
            return

class StreamListener():
    def __init__(self, stream):
        """
        stream: e.g, stdin/stdout<commit_msg>fixed typo<commit_after>import sys
import pickle
from threading import Thread
from Queue import Queue, Empty


# point is to make improbable that would ever happen to appear inside a pickled image and be mistaken
end_of_message_message = ("---EndOfMessage---"*10) + "\n"   

def send_to_stream(stream, msg): 
    """
    Pickle & send to stdout a message.
    Used primarily to communicate back-and-forth with a separately launched ztv process.
    """
    if isinstance(msg, str):
        msg = (msg,)
    pkl = pickle.dumps(msg)
    stream.write(pkl + '\n' + end_of_message_message)
    stream.flush()

class UnexpectedEndOfStream(Exception): pass

class StreamListenerTimeOut(Exception): pass

def _accumulate_to_queue(stream, queue):
    while True:
        line = stream.readline()
        if line:
            queue.put(line)
        else:
# TODO: rather than return, should really raise the Error, but then code elsewhere needs to be catching for it
#             raise UnexpectedEndOfStream
            return

class StreamListener():
    def __init__(self, stream):
        """
        stream: e.g, stdin/stdout
{'fraction_non_alphanumeric': 0.08738296923762817, 'fraction_numerical': 0.0017833259028087382, 'mean_word_length': 3.007142857142857, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6293419', 'n_tokens_mistral': 654, 'n_tokens_neox': 639, 'n_words': 224}