<commit_before>import os
import sys
import time
import errno
import threading
import subprocess

from atve import STRING_SET
from atve import PYTHON_VERSION
from atve.exception import *

class ThreadWithReturn(threading.Thread):
    def __init__(self, *args, **kwargs):
        super(ThreadWithReturn, self).__init__(*args, **kwargs)
        self._return = None

    def run(self):
        if self._Thread__target is not None:
            self._return = self._Thread__target(*self._Thread__args, **self._Thread__kwargs)

    def join(self, timeout=None):
        super(ThreadWithReturn, self).join(timeout=timeout)
        return self._return

def run(cmd, cwd=None, timeout=60, debug=False, shell=False):
    if type(cmd) in STRING_SET:
        cmd = [c for c in cmd.split() if c != '']
    if debug:
        sys.stderr.write(''.join(cmd) + '\n')
        sys.stderr.flush()

    try:
        if PYTHON_VERSION == 2:
            proc = subprocess.Popen(cmd,
                                    cwd     = cwd,
                                    stdout  = subprocess.PIPE,
                                    stderr  = subprocess.PIPE,
                                    shell   = shell)
            proc_thread = ThreadWithReturn(target=proc.communicate)
            proc_thread.start()
            result = proc_thread.join(timeout)
            if proc_thread.is_alive():
                try:
                    proc.kill()
                except OSError as e:
                    out = "{0}: {1}\n{2}".format(type(e).__name__, e, traceback.format_exc())
                    raise RunError(cmd, None, message='Raise Exception : %s' % out)
                raise TimeoutError({
                    'cmd'       : cmd,
                    'out'       : None,
                    'message'   : 'command %s is time out' % cmd
                })<commit_msg>update.<commit_after>import os
import sys
import time
import errno
import threading
import subprocess

from atve import STRING_SET
from atve import PYTHON_VERSION
from atve.exception import *

class ThreadWithReturn(threading.Thread):
    def __init__(self, *args, **kwargs):
        super(ThreadWithReturn, self).__init__(*args, **kwargs)
        self._return = None

    def run(self):
        if self._Thread__target is not None:
            self._return = self._Thread__target(*self._Thread__args, **self._Thread__kwargs)

    def join(self, timeout=None):
        super(ThreadWithReturn, self).join(timeout=timeout)
        return self._return

def run(cmd, cwd=None, timeout=60, debug=False, shell=False):
    if type(cmd) in STRING_SET:
        cmd = [c for c in cmd.split() if c != '']
    if debug:
        sys.stderr.write(''.join(cmd) + '\n')
        sys.stderr.flush()
    try:
        if PYTHON_VERSION == 2:
            proc = subprocess.Popen(cmd,
                                    cwd     = cwd,
                                    stdout  = subprocess.PIPE,
                                    stderr  = subprocess.PIPE,
                                    shell   = shell)
            proc_thread = ThreadWithReturn(target=proc.communicate)
            proc_thread.start()
            result = proc_thread.join(timeout)
            if proc_thread.is_alive():
                try:
                    proc.kill()
                except OSError as e:
                    out = "{0}: {1}\n{2}".format(type(e).__name__, e, traceback.format_exc())
                    raise RunError(cmd, None, message='Raise Exception : %s' % out)
                raise TimeoutError({
                    'cmd'       : cmd,
                    'out'       : None,
                    'message'   : 'command %s is time out' % cmd
                })
{'fraction_non_alphanumeric': 0.1030008110300081, 'fraction_numerical': 0.0032441200324412004, 'mean_word_length': 1.6334519572953736, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6735512', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1016, 'n_words': 252}