]> granicus.if.org Git - python/commit
[3.6] bpo-32591: fix abort in _PyErr_WarnUnawaitedCoroutine during shutdown (GH-5337...
authorT. Wouters <thomas@python.org>
Thu, 31 May 2018 10:20:46 +0000 (12:20 +0200)
committerGitHub <noreply@github.com>
Thu, 31 May 2018 10:20:46 +0000 (12:20 +0200)
commit500a419a7a68c32650717b213f0f5ab0461bb16b
tree63657ffbd653d3fb2ff6187999cac417da6e47f6
parent55d9e865cb3b50587c17c8a7beee090c4ac8d535
[3.6] bpo-32591: fix abort in _PyErr_WarnUnawaitedCoroutine during shutdown (GH-5337) (#6536)

When an unawaited coroutine is collected very late in shutdown --
like, during the final GC at the end of PyImport_Cleanup -- then it
was triggering an interpreter abort, because we'd try to look up the
"warnings" module and not only was it missing (we were prepared for
that), but the entire module system was missing (which we were not
prepared for).

I've tried to fix this at the source, by making the utility function
get_warnings_attr robust against this in general. Note that it already
has the convention that it can return NULL without setting an error,
which is how it signals that the attribute it was asked to fetch is
missing, and that all callers already check for NULL returns.

There's a similar check for being late in shutdown at the top of
warn_explicit, which might be unnecessary after this fix, but I'm not
sure so I'm going to leave it..
(cherry picked from commit dba976b8a28d6e5daa66ef31a6a7c694a9193f6a)

Co-authored-by: Nathaniel J. Smith <njs@pobox.com>
Python/_warnings.c