D7057: rust-utils: introduce a debug util to print the python stack trace

Alphare (Raphaël Gomès) phabricator at mercurial-scm.org
Wed Oct 16 10:23:33 EDT 2019


Closed by commit rHG886f0822a38e: rust-utils: introduce a debug util to print the python stack trace (authored by Alphare).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7057?vs=17064&id=17217

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7057/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7057

AFFECTED FILES
  rust/hg-cpython/src/lib.rs
  rust/hg-cpython/src/utils.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/utils.rs b/rust/hg-cpython/src/utils.rs
new file mode 100644
--- /dev/null
+++ b/rust/hg-cpython/src/utils.rs
@@ -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))
+}
diff --git a/rust/hg-cpython/src/lib.rs b/rust/hg-cpython/src/lib.rs
--- a/rust/hg-cpython/src/lib.rs
+++ b/rust/hg-cpython/src/lib.rs
@@ -35,6 +35,7 @@
 pub mod exceptions;
 pub mod filepatterns;
 pub mod parsers;
+pub mod utils;
 
 py_module_initializer!(rustext, initrustext, PyInit_rustext, |py, m| {
     m.add(



To: Alphare, #hg-reviewers, pulkit
Cc: gracinet, durin42, kevincox, mercurial-devel


More information about the Mercurial-devel mailing list