<commit_before># pytest framework ---------------------------------------------
import requests
from aquests.lib import siesta
from aquests.lib.pmaster import Puppet, processutil
import subprocess
import time
import sys
import os

class launch:
    def __init__ (self, script, port = 5000, ssl = False, silent = True):
        self.__script = script
        endpoint = "http{}://127.0.0.1".format (ssl and "s" or "")
        if port:
            endpoint += ":{}".format (port)
        self.__endpoint = endpoint
        self.__silent = silent
        self.__p = Puppet (communicate = False)        
        self.__requests = Requests (endpoint)
        self.__api = siesta.API (endpoint)
        self.__start ()
    
    def __enter__ (self):
        return self
        
    def __exit__ (self, type, value, tb):
        self._close ()

    def __getattr__ (self, attr):
        if attr in ("get", "post", "put", "patch", "delete", "head", "options"):
            return getattr (self.__requests, attr)
        else:
            return getattr (self.__api, attr)
        
    def __start (self):
        if self.__silent:
            self.__p.start ([sys.executable, self.__script, "-d"])
            self.__wait_until ("running")
        else:
            self.__p.start ([sys.executable, self.__script, "-v"])
            time.sleep (3)
                    
    def __wait_until (self, status, timeout = 10):
        for i in range (timeout):
            command = "{} {} status".format (sys.executable, self.__script)
            res = subprocess.run (command, shell = True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)    
            out, err = res.stdout.decode ("utf8"), res.stderr.decode ("utf8")
            if out.find (status) != -1:
                break
            time.sleep (1) 
    
    def _close (self):
        if self.__silent:
            self.__p.start ([sys.executable, self.__script, "stop"])
            self.__wait_until ("stopped")<commit_msg>fix launch: check daemon weather it is running<commit_after># pytest framework ---------------------------------------------
import requests
from aquests.lib import siesta
from aquests.lib.pmaster import Puppet, processutil
import subprocess
import time
import sys
import os

class launch:
    def __init__ (self, script, port = 5000, ssl = False, silent = True):
        self.__script = script
        endpoint = "http{}://127.0.0.1".format (ssl and "s" or "")
        if port:
            endpoint += ":{}".format (port)
        self.__endpoint = endpoint
        self.__silent = silent
        self.__servicing = False
        self.__p = Puppet (communicate = False)        
        self.__requests = Requests (endpoint)
        self.__api = siesta.API (endpoint)
        self.__start ()
    
    def __enter__ (self):
        return self
        
    def __exit__ (self, type, value, tb):
        self._close ()

    def __getattr__ (self, attr):
        if attr in ("get", "post", "put", "patch", "delete", "head", "options"):
            return getattr (self.__requests, attr)
        else:
            return getattr (self.__api, attr)
        
    def __start (self):
        if self.__silent:
            if self.__is_running ():
                self.__servicing = True
            else:    
                self.__p.start ([sys.executable, self.__script, "-d"])
                self.__wait_until ("running")
        else:
            self.__p.start ([sys.executable, self.__script, "-v"])
            time.sleep (3)
    
    def __is_running (self):
        command = "{} {} status".format (sys.executable, self.__script)
        res = subprocess.run (command, shell = True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)    
        out, err = res.stdout.decode ("utf8"), res.stderr.decode ("utf8")
        return out.find ("running") != -1
                             
    def __wait_until (self, status, timeout = 10):
        for i in range (timeout):
            command = "{} {} status".format (sys.executable, self.__script)
            res = subprocess.run (command, shell = True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)    
            out, err = res.stdout.decode ("utf8"), res.stderr.decode ("utf8")
            if out.find (status) != -1:
                return True
            time.sleep (1) 
        return False    
    
    def _close (self):
        if self.__silent and not self.__servicing:
            self.__p.start ([sys.executable, self.__script, "stop"])
            self.__wait_until ("stopped")
{'fraction_non_alphanumeric': 0.13954515345550894, 'fraction_numerical': 0.008169573857363657, 'mean_word_length': 1.836568566061365, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '465412', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1271, 'n_words': 371}