]> granicus.if.org Git - python/commitdiff
bpo-33623: Fix possible SIGSGV when asyncio.Future is created in __del__ (#7080)
authorYury Selivanov <yury@magic.io>
Mon, 28 May 2018 15:11:31 +0000 (11:11 -0400)
committerGitHub <noreply@github.com>
Mon, 28 May 2018 15:11:31 +0000 (11:11 -0400)
Misc/NEWS.d/next/Library/2018-05-23-14-58-05.bpo-33623.wAw1cF.rst [new file with mode: 0644]
Modules/_asynciomodule.c

diff --git a/Misc/NEWS.d/next/Library/2018-05-23-14-58-05.bpo-33623.wAw1cF.rst b/Misc/NEWS.d/next/Library/2018-05-23-14-58-05.bpo-33623.wAw1cF.rst
new file mode 100644 (file)
index 0000000..641874c
--- /dev/null
@@ -0,0 +1 @@
+Fix possible SIGSGV when asyncio.Future is created in __del__
index 6d7249a580097e755f569aab137408cb106c8601..c4d19034ce4583ec006216e90a15291407bb8f5c 100644 (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;