import sys

class multi_threaded:
    def __init__(self, count):
        self.count = count

    def __enter__(self):
        self.old_locals = sys._getframe(1).f_locals.copy()

    def __exit__(self, exc_type, exc_val, exc_tb):
        new_locals = sys._getframe(1).f_locals
        funcs = list(map(new_locals.get, new_locals.keys() - self.old_locals.keys()))
        my_slice = int(self.count / len(funcs))
        for i, func in enumerate(funcs):
            start = my_slice * i
            func(start, start + my_slice)

def spawn_many():
    dataset = [1, 2, 3, 4, 5]
    with multi_threaded(len(dataset)):
        def foo(start_idx, end):
            print("foo" + str(dataset[start_idx : end]))
        def bar(start_idx, end):
            print("bar" + str(dataset[start_idx : end]))

spawn_many()