bpo-33623: Fix possible SIGSGV when asyncio.Future is created in __de… · python/cpython@35230d0

Original file line numberDiff line numberDiff line change

@@ -501,7 +501,13 @@ future_init(FutureObj *fut, PyObject *loop)

501501

if (is_true < 0) {

502502

return -1;

503503

}

504-

if (is_true) {

504+

if (is_true && !_Py_IsFinalizing()) {

505+

/* Only try to capture the traceback if the interpreter is not being

506+

finalized. The original motivation to add a `_Py_IsFinalizing()`

507+

call was to prevent SIGSEGV when a Future is created in a __del__

508+

method, which is called during the interpreter shutdown and the

509+

traceback module is already unloaded.

510+

*/

505511

fut->fut_source_tb = _PyObject_CallNoArg(traceback_extract_stack);

506512

if (fut->fut_source_tb == NULL) {

507513

return -1;