diff options
Diffstat (limited to 'Modules/_lsprof.c')
-rw-r--r-- | Modules/_lsprof.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index 5d18c33..41c477e 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -150,7 +150,16 @@ static PY_LONG_LONG CallExternalTimer(ProfilerObject *pObj) } Py_DECREF(o); if (PyErr_Occurred()) { - PyErr_WriteUnraisable((PyObject *) pObj); + PyObject *context = (PyObject *)pObj; + /* May have been called by profiler_dealloc(). */ + if (Py_REFCNT(context) < 1) { + context = PyString_FromString("profiler calling an " + "external timer"); + if (context == NULL) { + return 0; + } + } + PyErr_WriteUnraisable(context); return 0; } return result; |