mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
Updated Debugging segfaults and hard to decipher pybind11 bugs (markdown)
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)
|
||||
|
Loading…
Reference in New Issue
Block a user