From 02e34745d427438ba9a635aded8091238c9826d5 Mon Sep 17 00:00:00 2001 From: Eric Cousineau Date: Thu, 4 Mar 2021 17:24:55 -0500 Subject: [PATCH] Updated Debugging segfaults and hard to decipher pybind11 bugs (markdown) --- Debugging-segfaults-and-hard-to-decipher-pybind11-bugs.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Debugging-segfaults-and-hard-to-decipher-pybind11-bugs.md b/Debugging-segfaults-and-hard-to-decipher-pybind11-bugs.md index ea49b79..17b6e62 100644 --- a/Debugging-segfaults-and-hard-to-decipher-pybind11-bugs.md +++ b/Debugging-segfaults-and-hard-to-decipher-pybind11-bugs.md @@ -5,6 +5,7 @@ This is meant to aide in debugging hard-to-decipher pybind11 bugs (or surprises Generally, it's easiest to get a sense of where things are failing by using the `trace` module. Here's some code that can be copied+pasted. For examples here, assume these functions are defined in `debug.py` (Python 3.5+ only): ```py +# -*- coding: utf-8 -*- """ Utilities that should be synchronized with: https://drake.mit.edu/python_bindings.html#debugging-with-the-python-bindings @@ -16,24 +17,24 @@ def reexecute_if_unbuffered(): ONLY use this at your entrypoint. Otherwise, you may have code be re-executed that will clutter your console.""" import os - import shlex import sys + if os.environ.get("PYTHONUNBUFFERED") in (None, ""): os.environ["PYTHONUNBUFFERED"] = "1" argv = list(sys.argv) if argv[0] != sys.executable: argv.insert(0, sys.executable) - cmd = " ".join([shlex.quote(arg) for arg in argv]) sys.stdout.flush() os.execv(argv[0], argv) def traced(func, ignoredirs=None): """Decorates func such that its execution is traced, but filters out any - Python code outside of the system prefix.""" + Python code outside of the system prefix.""" import functools import sys import trace + if ignoredirs is None: ignoredirs = ["/usr", sys.prefix] tracer = trace.Trace(trace=1, count=0, ignoredirs=ignoredirs)