(trace_filename: str, sys_stdout)
return _trace
Ref: http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing_python_code.html
Ref: http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing_python_code.html
Ref : http : // www . dalkescientific . com / writings / diary / archive / 2005 / 04 / 20 / tracing_python_code . html
def gen_tracefunc(trace_filename: str, sys_stdout):
    """
    Ref: http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing_python_code.html
    """

    def _trace(frame, event, arg):
        if event == "line":
            lineno = frame.f_lineno - 1  # set lineno starts from 0
            filename = frame.f_globals.get("__file__")

            if filename == trace_filename:
                line = getline(filename, lineno).rstrip()

                sys_stdout.write("LNO:{}\n".format(lineno))
                sys_stdout.write(f"DBG:{lineno:3d} {line}\n")
                sys_stdout.flush()
                # time.sleep(.5)

        return _trace

    return _trace
def gen_tracefunc ( trace_filename : str , sys_stdout ) : def _trace ( frame , event , arg ) : if event == "line" : lineno = frame . f_lineno - 1 # set lineno starts from 0 filename = frame . f_globals . get ( "__file__" ) if filename == trace_filename : line = getline ( filename , lineno ) . rstrip ( ) sys_stdout . write ( "LNO:{}\n" . format ( lineno ) ) sys_stdout . write ( f"DBG:{lineno:3d} {line}\n" ) sys_stdout . flush ( ) # time.sleep(.5) return _trace return _trace