Skip to content

Commit

Permalink
HPCC-31004 Add some stack trace information to exceptions passed back…
Browse files Browse the repository at this point in the history
… from Python

Signed-off-by: Richard Chapman <[email protected]>
  • Loading branch information
richardkchapman committed Jan 3, 2024
1 parent 272a004 commit 639ecad
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions plugins/py3embed/py3embed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
#include "enginecontext.hpp"
#include <regex>

#if defined (__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
#include <execinfo.h> // comment out if not present
#define HAS_BACKTRACE
#endif

#if PY_MAJOR_VERSION >=3
#define Py_TPFLAGS_HAVE_ITER 0
#endif
Expand Down Expand Up @@ -131,6 +136,14 @@ static void failx(const char *message, ...)
StringBuffer msg;
msg.append("pyembed: ").valist_appendf(message,args);
va_end(args);
#ifdef HAS_BACKTRACE
void *stack[5];
unsigned nFrames = backtrace(stack, 5);
char** strs = backtrace_symbols(stack, nFrames);
for (unsigned i = 0; i < nFrames; ++i)
msg.append("\n ").append(strs[i]);
free(strs);
#endif
rtlFail(0, msg.str());
}

Expand Down Expand Up @@ -383,6 +396,9 @@ static bool releaseContext(bool isPooled)
return false;
}

// GILUnblock ensures the we release the Python "Global interpreter lock" for the appropriate duration


// Use a global object to ensure that the Python interpreter is initialized on main thread

static HINSTANCE keepLoadedHandle;
Expand Down

0 comments on commit 639ecad

Please sign in to comment.