global_stack = [] def exported_function(param): global global_stack global_stack = [] fill_global_stack_with_possible_solutions(param) for sol in global_stack: check_solution(sol, param) # if exported_function is called by 2 or more concurrent threads, they may interfere with each other, and there is a strong possibility that it will be called like that