Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 35230d0

Browse files
authored
bpo-33623: Fix possible SIGSGV when asyncio.Future is created in __del__ (#7080)
1 parent 08c5aca commit 35230d0

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix possible SIGSGV when asyncio.Future is created in __del__

Modules/_asynciomodule.c

Lines changed: 7 additions & 1 deletion
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;

0 commit comments

Comments
 (0)