<commit_before>import threading
from decider import *
from libs_procmon import *

class Process(object):
    proc = None
    name = None
    args = None
    searchInterval = 0.5 
    
    def __init__(self, exename, args):
        self.name = exename
        self.args = args
 
    #search the file in the name, then search other args in the cmdline    
    def find_proc(self):
        pids=[]
        for proc in psutil.process_iter():
            if any(self.name in s for s in proc.cmdline()): #and not any(sys.argv[0] in s for s in proc.cmdline())
                if self.name.find(proc.name()) > 0:
                    if any(self.args in s for s in proc.cmdline()):
                        debug_msg("process pid is "+str(proc.pid))
                        pids.append(proc.pid)
        if len(pids) == 0:
            return None
        return pids
    
    #actually populate class finding the pid, will be blocked until is found
    def init(self):
        while True:
            pids = find_proc()
            #actually better catch this, even if still early
            if pids != None:
                if len(pids) > 1:
                    debug_msg("found %d process, will monitor %d" % (len(pids), pids[0] ))
                self.proc=psutil.Process(pids[0])
                if not self.proc.is_running():
                    debug_msg('process dead before starting timer')
                    return
                break
            if pids == None:
                debug_msg("process not found, keep searching")
            time.sleep(self.searchInterval)
    
    #a good example of proxy that is never used
    def get_pid(self):
        return self.proc.pid


class ProcMon(object):
    pipename="/tmp/monitor_pipe0"
    savedir="saved"
    debugFlag=True
    save_arg=True #will affect decision to save or not long running testcases
    processTimeout=20
    timeout=None
    pipe_event=None
    timer=None
    listener=None
    process=None
    
    def __init__(self, exeFile, exeArgs):
        timeout=threading.Event()
        pipe_event=threading.Event()
        self.exeFile = exeFile
        self.exeArgs = exeArgs
        self.process = Process(self.exeFile, self.exeArgs)
        
    def timer_thread(self):
        time.sleep(self.processTimeout)
        self.timeout.set()
    
    def getSigma2(l, mean):
        s2=[]
        for i in l:
            s2.append(i*i)
        return (sum(s2)/len(s2))-(mean*mean)
    
    #run in his own thread, occasionally read pipe, if anything was written verify with stored data
    def monitor_listener():
        global pipename
        return

    #immediately kill and exit
    def kill_proc_and_exit(p):
        p.kill()
        debug_msg("exiting")
        sys.exit(0)
        
    def start(self):
        debug_msg("starting search for process %s with args \"%s\"" % (exeFile, exeArgs))<commit_msg>fixes<commit_after>import threading
from decider import *
from libs_procmon import *

class Process(object):
    proc = None
    name = None
    args = None
    searchInterval = 0.5 
    
    def __init__(self, exename, args):
        self.name = exename
        self.args = args
 
    #search the file in the name, then search other args in the cmdline    
    def find_proc(self):
        pids=[]
        for proc in psutil.process_iter():
            if any(self.name in s for s in proc.cmdline()): #and not any(sys.argv[0] in s for s in proc.cmdline())
                if self.name.find(proc.name()) > 0:
                    if any(self.args in s for s in proc.cmdline()):
                        debug_msg("process pid is "+str(proc.pid))
                        pids.append(proc.pid)
        if len(pids) == 0:
            return None
        return pids
    
    #actually populate class finding the pid, will be blocked until is found
    def init(self):
        while True:
            pids = find_proc()
            #actually better catch this, even if still early
            if pids != None:
                if len(pids) > 1:
                    debug_msg("found %d process, will monitor %d" % (len(pids), pids[0] ))
                self.proc=psutil.Process(pids[0])
                if not self.proc.is_running():
                    debug_msg('process dead before starting timer')
                    return
                break
            if pids == None:
                debug_msg("process not found, keep searching")
            time.sleep(self.searchInterval)
    
    #a good example of proxy that is never used
    def get_pid(self):
        return self.proc.pid


class ProcMon(object):
    pipename="/tmp/monitor_pipe0"
    savedir="saved"
    debugFlag=True
    save_arg=True #will affect decision to save or not long running testcases
    processTimeout=20
    timeout=None
    pipe_event=None
    timer=None
    listener=None
    process=None
    
    def __init__(self, exeFile, exeArgs):
        timeout=threading.Event()
        pipe_event=threading.Event()
        self.exeFile = exeFile
        self.exeArgs = exeArgs
        self.process = Process(self.exeFile, self.exeArgs)
        
    def timer_thread(self):
        time.sleep(self.processTimeout)
        self.timeout.set()
    
    def getSigma2(l, mean):
        s2=[]
        for i in l:
            s2.append(i*i)
        return (sum(s2)/len(s2))-(mean*mean)
    
    #run in his own thread, occasionally read pipe, if anything was written verify with stored data
    def monitor_listener():
        global pipename
        return

    #immediately kill and exit
    def kill_proc_and_exit(p):
        p.kill()
        debug_msg("exiting")
        sys.exit(0)
        
    def start(self):
        debug_msg("starting search for process %s with args \"%s\"" % (self.exeFile, self.exeArgs))
{'fraction_non_alphanumeric': 0.09236111111111112, 'fraction_numerical': 0.005902777777777778, 'mean_word_length': 1.8733167082294264, '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': '1136599', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1660, 'n_words': 501}