""")
assert_python_ok("-c", code)
+ def test_warnings_fini(self):
+ # See https://github.com/python/cpython/issues/137384
+ code = textwrap.dedent('''
+ import asyncio
+ from contextvars import ContextVar
+
+ context_loop = ContextVar("context_loop", default=None)
+ loop = asyncio.new_event_loop()
+ context_loop.set(loop)
+ ''')
+
+ assert_python_ok("-c", code)
+
def setUpModule():
global enabled, debug
_Py_ClearExecutorDeletionList(interp);
#endif
_PyAST_Fini(interp);
- _PyWarnings_Fini(interp);
_PyAtExit_Fini(interp);
// All Python types must be destroyed before the last GC collection. Python
_PyGC_CollectNoFail(tstate);
_PyGC_Fini(interp);
+ // Finalize warnings after last gc so that any finalizers can
+ // access warnings state
+ _PyWarnings_Fini(interp);
/* We don't clear sysdict and builtins until the end of this function.
Because clearing other attributes can execute arbitrary Python code
which requires sysdict and builtins. */