tensorflow/python/util/tf_stack.cc
// Returns contents of the line corresponding to the given frame.
//
// Precondition: must be holding Python GIL.
Returns contents of the line corresponding to the given frame.
Precondition: must be holding Python GIL.
Returns contents of the line corresponding to the given frame . Precondition : must be holding Python GIL .
py::str LineContents(const StackFrame& frame) {
  DCheckPyGilStateForStackTrace();
  static const auto* inspect = new py::module(py::module::import("inspect"));
  static const auto* getmodule = new py::function(inspect->attr("getmodule"));
  static const auto* linecache =
      new py::module(py::module::import("linecache"));
  static const auto* checkcache =
      new py::function(linecache->attr("checkcache"));
  static const auto* getline = new py::function(linecache->attr("getline"));
  (*checkcache)(py::str(frame.file_name));
  const auto& module = (*getmodule)(py::none(), py::str(frame.file_name));
  py::object dict = py::none();
  if (!module.is_none()) {
    dict = module.attr("__dict__");
  }
  return py::cast<py::str>(
      (*getline)(py::str(frame.file_name), py::int_(frame.line_number), dict)
          .attr("strip")());
}
py :: str LineContents ( const StackFrame & frame ) { DCheckPyGilStateForStackTrace ( ) ; static const auto * inspect = new py :: module ( py :: module :: import ( " " ) ) ; static const auto * getmodule = new py :: function ( inspect -> attr ( " " ) ) ; static const auto * linecache = new py :: module ( py :: module :: import ( " " ) ) ; static const auto * checkcache = new py :: function ( linecache -> attr ( " " ) ) ; static const auto * getline = new py :: function ( linecache -> attr ( " " ) ) ; ( * checkcache ) ( py :: str ( frame . file_name ) ) ; const auto & module = ( * getmodule ) ( py :: none ( ) , py :: str ( frame . file_name ) ) ; py :: object dict = py :: none ( ) ; if ( ! module . is_none ( ) ) { dict = module . attr ( " " ) ; } return py :: cast < py :: str > ( ( * getline ) ( py :: str ( frame . file_name ) , py :: int_ ( frame . line_number ) , dict ) . attr ( " " ) ( ) ) ; }
Returns contents of the line corresponding to the given frame.
Returns contents of the line corresponding to the given frame .
// Pointers are to avoid static destruction of pybind::object, which // occurs in uncontrollable states. // Here we use the undocumented second argument of inspect.getmodule to look // up a module from a filename. It has been unchanged since 2015. // module dict is used by getline to resolve import hooks; see the // stdlib's inspect module.