parameters: (trace_filename: str, sys_stdout)
return_statement: return _trace
docstring: Ref: http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing_python_code.html
docstring_summary: Ref: http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing_python_code.html
docstring_tokens: Ref : http : // www . dalkescientific . com / writings / diary / archive / 2005 / 04 / 20 / tracing_python_code . html
function: 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
function_tokens: 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