<commit_before>import multiprocessing as mulproc

class GPUMapper(object):

    def __init__(self, n_walkers, n_workers):

        # TODO add comments describing what is going on
        self.free_workers= mulproc.Queue()
        self.lock = mulproc.Semaphore (n_workers)
        self.results_list = mulproc.Manager().list()
        for i in range(n_walkers):
            self.results_list.append(None)
        for i in range (n_workers):
            self.free_workers.put(i)

    def exec_call(self, _call_, index, *args):
        # gets a free GPU and calls the runnable function
        self.lock.acquire()
        gpu_index = self.free_workers.get()
        result = _call_(*args, DeviceIndex=gpu_index)

        self.free_workers.put(gpu_index)
        self.results_list[index] = result
        self.lock.release()


    def map(self, _call_, *iterables):

        walkers_pool = []
        # create processes and start to run
        index = 0

        for args in zip(*iterables):
            walkers_pool.append(mulproc.Process(target=self.exec_call,
                                                args=(_call_,index,*args)))
            index += 1

        for p in walkers_pool:
            p.start()

        for p in walkers_pool:
            p.join()


        return self.results_list
<commit_msg>wrapped platform index in string<commit_after>import multiprocessing as mulproc

class GPUMapper(object):

    def __init__(self, n_walkers, n_workers):

        # TODO add comments describing what is going on
        self.free_workers= mulproc.Queue()
        self.lock = mulproc.Semaphore(n_workers)
        self.results_list = mulproc.Manager().list()
        for i in range(n_walkers):
            self.results_list.append(None)
        for i in range (n_workers):
            self.free_workers.put(i)

    def exec_call(self, _call_, index, *args):
        # gets a free GPU and calls the runnable function
        self.lock.acquire()
        gpu_index = self.free_workers.get()
        result = _call_(*args, DeviceIndex=str(gpu_index))

        self.free_workers.put(gpu_index)
        self.results_list[index] = result
        self.lock.release()


    def map(self, _call_, *iterables):

        walkers_pool = []
        # create processes and start to run
        index = 0

        for args in zip(*iterables):
            walkers_pool.append(mulproc.Process(target=self.exec_call,
                                                args=(_call_,index,*args)))
            index += 1

        for p in walkers_pool:
            p.start()

        for p in walkers_pool:
            p.join()


        return self.results_list

{'fraction_non_alphanumeric': 0.09142425387230828, 'fraction_numerical': 0.001511144692104269, 'mean_word_length': 2.0228310502283104, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '321716', 'n_tokens_mistral': 784, 'n_tokens_neox': 755, 'n_words': 189}