Hi, 2015-02-06 0:27 GMT+01:00 Francis Giraldeau <francis.girald...@gmail.com>: > I need to access frame members from within a signal handler for tracing > purpose.
IMO you have a big technical or design issue here. Accessing Python internals in a signal handler is not reliable. A signal can occur anytime, between two instructions. > However, the function PyUnicode_AsUTF8String() calls PyObject_Malloc(), > which is not reentrant. If the signal handler nest over PyObject_Malloc(), > it causes a segfault, and it could also deadlock. Yes, the list of async signal-safe function is very very short :-) It's something like: read(), write(), and use the stack (but not too much stack or you will get a stack overflow). I spent many weeks to implement the faulthandler module (try to write a safe and portable implementation). To write the traceback, I only use write(). But to read the traceback, I inspect Python internals which is completly unsafe. faulthandler is written to only be called when something really bad happen (a "crash"), so it's not so important if it does crash too :-) See also the tracemalloc module which also inspects the traceback, but it does *not* use signals (which would be unsafe). It uses hooks on the memory allocator. Python has sys.settrace() and sys.setprofile(). Why not using these functions? Victor _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com