Mercurial > public > mercurial-scm > hg-stable
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rust/hg-cpython/src/utils.rs Mon Oct 07 23:17:44 2019 +0200 @@ -0,0 +1,13 @@ +use cpython::{PyDict, PyObject, PyResult, PyTuple, Python}; + +#[allow(unused)] +pub fn print_python_trace(py: Python) -> PyResult<PyObject> { + eprintln!("==============================="); + eprintln!("Printing Python stack from Rust"); + eprintln!("==============================="); + let traceback = py.import("traceback")?; + let sys = py.import("sys")?; + let kwargs = PyDict::new(py); + kwargs.set_item(py, "file", sys.get(py, "stderr")?)?; + traceback.call(py, "print_stack", PyTuple::new(py, &[]), Some(&kwargs)) +}