Updated Debugging segfaults and hard to decipher pybind11 bugs (markdown)

Eric Cousineau 2021-03-04 17:24:55 -05:00
parent cf07724242
commit 02e34745d4

@ -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,14 +17,13 @@ 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)
@ -34,6 +34,7 @@ def traced(func, ignoredirs=None):
import functools
import sys
import trace
if ignoredirs is None:
ignoredirs = ["/usr", sys.prefix]
tracer = trace.Trace(trace=1, count=0, ignoredirs=ignoredirs)