rust/hg-cpython/src/utils.rs
author Yuya Nishihara <yuya@tcha.org>
Sun, 15 Sep 2019 22:06:19 +0900
changeset 43284 ce6dd1cee4c8
parent 43251 970978975574
child 44505 d738b7a18438
permissions -rw-r--r--
rust-cpython: put leaked reference in PyLeakedRef The next patch will make PyLeakedRef manage the lifetime of the underlying object. leak_handle.data.take() will be removed soon.

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))
}