bpo-33623: Fix possible SIGSGV when asyncio.Future is created in __del__ (GH-7080)

(cherry picked from commit 35230d08e0)

Co-authored-by: Yury Selivanov <yury@magic.io>
This commit is contained in:
Miss Islington (bot) 2018-05-28 08:28:12 -07:00 committed by GitHub
parent 983c1ba94a
commit 51d0a2c8dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -0,0 +1 @@
Fix possible SIGSGV when asyncio.Future is created in __del__

View File

@ -501,7 +501,13 @@ future_init(FutureObj *fut, PyObject *loop)
if (is_true < 0) {
return -1;
}
if (is_true) {
if (is_true && !_Py_IsFinalizing()) {
/* Only try to capture the traceback if the interpreter is not being
finalized. The original motivation to add a `_Py_IsFinalizing()`
call was to prevent SIGSEGV when a Future is created in a __del__
method, which is called during the interpreter shutdown and the
traceback module is already unloaded.
*/
fut->fut_source_tb = _PyObject_CallNoArg(traceback_extract_stack);
if (fut->fut_source_tb == NULL) {
return -1;