<commit_before>"""Base class for a profile wrapper."""
import multiprocessing
import os
import sys
import zlib


def get_package_code(package_path):
    """Returns package source code.

    Args:
        package_path: Path to Python package.
    Returns:
        A dict containing non-compiled and compiled code for package
        specified by package name.
    """
    import pkgutil

    all_code = {}
    for fobj, modname, _ in pkgutil.iter_modules(path=[package_path]):
        filename = os.path.join(fobj.path, '%s.py' % modname)
        if os.path.exists(filename):
            with open(filename, 'r') as srcfile:
                src_code = srcfile.read()
                compiled_code = compile(src_code, package_path, 'exec')
                all_code[filename] = src_code, compiled_code
    return all_code


def hash_name(name):
    """Hash name and trim resulting hash."""
    return zlib.adler32(name.encode('utf-8'))


class ProcessWithException(multiprocessing.Process):
    """Process subclass that propagates exceptions to parent process."""

    def __init__(self, *args, **kwargs):
        super(self.__class__, self).__init__(*args, **kwargs)
        self.parent_conn, self.child_conn = multiprocessing.Pipe()

    def run(self):
        try:
            super(self.__class__, self).run()
            self.child_conn.send(None)
        except Exception as exc:  # pylint: disable=broad-except
            self.child_conn.send(exc)

    @property
    def exception(self):
        """Returns exception from child process."""
        return self.parent_conn.recv()


def run_in_another_process(func):
    """Runs wrapped function in separate process.

    Function arguments and output should be serializable.
    """<commit_msg>Fix commend for hash_name function.<commit_after>"""Base class for a profile wrapper."""
import multiprocessing
import os
import sys
import zlib


def get_package_code(package_path):
    """Returns package source code.

    Args:
        package_path: Path to Python package.
    Returns:
        A dict containing non-compiled and compiled code for package
        specified by package name.
    """
    import pkgutil

    all_code = {}
    for fobj, modname, _ in pkgutil.iter_modules(path=[package_path]):
        filename = os.path.join(fobj.path, '%s.py' % modname)
        if os.path.exists(filename):
            with open(filename, 'r') as srcfile:
                src_code = srcfile.read()
                compiled_code = compile(src_code, package_path, 'exec')
                all_code[filename] = src_code, compiled_code
    return all_code


def hash_name(name):
    """Hashes name and trims resulting hash."""
    return zlib.adler32(name.encode('utf-8'))


class ProcessWithException(multiprocessing.Process):
    """Process subclass that propagates exceptions to parent process."""

    def __init__(self, *args, **kwargs):
        super(self.__class__, self).__init__(*args, **kwargs)
        self.parent_conn, self.child_conn = multiprocessing.Pipe()

    def run(self):
        try:
            super(self.__class__, self).run()
            self.child_conn.send(None)
        except Exception as exc:  # pylint: disable=broad-except
            self.child_conn.send(exc)

    @property
    def exception(self):
        """Returns exception from child process."""
        return self.parent_conn.recv()


def run_in_another_process(func):
    """Runs wrapped function in separate process.

    Function arguments and output should be serializable.
    """
{'fraction_non_alphanumeric': 0.1036637318943482, 'fraction_numerical': 0.0017040613462084636, 'mean_word_length': 2.8366013071895426, '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': '3912887', 'n_tokens_mistral': 1020, 'n_tokens_neox': 976, 'n_words': 280}