comparison rust/hg-cpython/src/utils.rs @ 43251:970978975574

rust-utils: introduce a debug util to print the python stack trace Differential Revision: https://phab.mercurial-scm.org/D7057
author Raphaël Gomès <rgomes@octobus.net>
date Mon, 07 Oct 2019 23:17:44 +0200
parents
children d738b7a18438
comparison
equal deleted inserted replaced
43250:98d996a138de 43251:970978975574
1 use cpython::{PyDict, PyObject, PyResult, PyTuple, Python};
2
3 #[allow(unused)]
4 pub fn print_python_trace(py: Python) -> PyResult<PyObject> {
5 eprintln!("===============================");
6 eprintln!("Printing Python stack from Rust");
7 eprintln!("===============================");
8 let traceback = py.import("traceback")?;
9 let sys = py.import("sys")?;
10 let kwargs = PyDict::new(py);
11 kwargs.set_item(py, "file", sys.get(py, "stderr")?)?;
12 traceback.call(py, "print_stack", PyTuple::new(py, &[]), Some(&kwargs))
13 }