def get_stack(message=None, stack_first_frame=1, max_frames=15):
    try:
        stack = inspect.stack()
        frame_num = stack_first_frame
        context = []
        while len(stack) > frame_num and frame_num < (max_frames + stack_first_frame):
            exec_line = "%s:%s:%s" % (stack[frame_num][1], stack[frame_num][2], stack[frame_num][3])
            context.insert(0, exec_line)
            if exec_line.endswith("_control_flow") or exec_line.endswith("load_ion") or exec_line.endswith("spawn_process")\
                or exec_line.endswith(":main") or exec_line.endswith(":dispatch_request"):
                break
            frame_num += 1
        stack_str = "\n ".join(context)
        if message:
            stack_str = message + "\n" + stack_str
        return stack_str
    except Exception as ex:
        stack_str = "ERROR: " + str(ex)
        if message:
            stack_str = message + "\n" + stack_str
        return stack_str
dataset/ETHPy150Open ooici/pyon/pyon/util/breakpoint.py/get_stack/original