<commit_before>#!/usr/bin/env python

import logging
from multiprocessing.dummy import Pool
import os
import time

import begin
import coloredlogs
from tqdm import tqdm

from client import QueryClient, ModifyClient
from ltu.engine.result import Result


logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

def get_action_name_from_function(function):
    """return from a function (add_image, search_image, delete_image) the name of the action concerned
    """
    return function.__name__.split('_')[0]

def run_single_task(items):
    """Run given action for one file
    """
    in_file = items[0]["in"]
    action_function = items[1]
    action = get_action_name_from_function(items[1])
    out_file = items[0][action]

    #launch action
    result = action_function(in_file)

    #save the result in a json file
    result.save_json(out_file)
    print ("Result ", result)




def run_task_mono_thread(action_function, files, action_label, force_action=True, nb_threads=1, offset=0):
    """Run given action on every files, one at a time.
    """
    items = ()

    for file in files[offset:]:
        items = (file,action_function)
        print("%s: %s" % (action_label, file["in"]))
        run_single_task(items)

def run_task_multi_thread(action_function, files, action_label, force_action=True, nb_threads=2, offset=0):
    """Run given action on every files using a threading pool.
       It uses a progress bar instead of a usual verbose log.
    """
    pool = Pool(processes=nb_threads)
    items = [(file, action_function) for file in files[offset:]]
    pool_iterable = pool.imap_unordered(run_single_task, items)
    progress_bar_items = tqdm(total=len(items),<commit_msg>remove print("Result") and un necessary space<commit_after>#!/usr/bin/env python

import logging
from multiprocessing.dummy import Pool
import os
import time

import begin
import coloredlogs
from tqdm import tqdm

from client import QueryClient, ModifyClient
from ltu.engine.result import Result


logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

def get_action_name_from_function(function):
    """return from a function (add_image, search_image, delete_image) the name of the action concerned
    """
    return function.__name__.split('_')[0]

def run_single_task(items):
    """Run given action for one file
    """
    in_file = items[0]["in"]
    action_function = items[1]
    action = get_action_name_from_function(items[1])
    out_file = items[0][action]

    #launch action
    result = action_function(in_file)

    #save the result in a json file
    result.save_json(out_file)
    
def run_task_mono_thread(action_function, files, action_label, force_action=True, nb_threads=1, offset=0):
    """Run given action on every files, one at a time.
    """
    items = ()

    for file in files[offset:]:
        items = (file,action_function)
        print("%s: %s" % (action_label, file["in"]))
        run_single_task(items)

def run_task_multi_thread(action_function, files, action_label, force_action=True, nb_threads=2, offset=0):
    """Run given action on every files using a threading pool.
       It uses a progress bar instead of a usual verbose log.
    """
    pool = Pool(processes=nb_threads)
    items = [(file, action_function) for file in files[offset:]]
    pool_iterable = pool.imap_unordered(run_single_task, items)
    progress_bar_items = tqdm(total=len(items),
{'fraction_non_alphanumeric': 0.10078878177037687, 'fraction_numerical': 0.0052585451358457495, 'mean_word_length': 4.243491577335376, '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': '1729523', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1065, 'n_words': 303}