A python module using multi-threading to speed up bulk and repetitive function calls, which can be imported after adding repetitive.py to your project directory
import repetitiverepetitive.SingleFunc(func, num_threads = 10, verbose = True)Creates a SingleFunc object
func: desired function to be runnum_threads: number of threads to be used (optional, defaults to 10)verbose:TrueorFalse- ifTrue, shows a progress bar usingtqdmwhen running the function
Creates self.num_threads number of threads and runs the function self.func using the arguments provided in args_lst.
SingleFunc.run_all(args_lst, pbar_pos = 0, desc = 'progress') -> listargs_lst: list of tuples containing the arguments to the functionpbar_pos: position of thetqdmprogress bar (optional, defaults to 0); ignore ifself.verboseis Falsedesc:string, description of thetqdmprogress bar (optional, defaults to "progress"); ignore ifself.verboseis False
List of return values from the function calls corresponding to the respective tuples of arguments from args_lst
import time
import threading
from tqdm import tqdm
from repetitive import SingleFunc
def func1():
tqdm.write(str(threading.get_ident()))
time.sleep(1)
return threading.get_ident()
F = SingleFunc(func1, 5)
lst = [() for _ in range(20)]
out = F.run_all(lst, 0)
print(len(out)) # prints '20'- decorator