bpo-24596: Decref module in PyRun_SimpleFileExFlags() on SystemExit#7918
Conversation
PyErr_Print() will not return when the exception is a SystemExit, so decref the __main__ module object in that case.
| flush_io(); | ||
| if (v == NULL) { | ||
| if (PyErr_ExceptionMatches(PyExc_SystemExit)) { | ||
| Py_DECREF(m); |
There was a problem hiding this comment.
Why make this a special case? We could just always Py_DECREF(m) early.
There was a problem hiding this comment.
No. Py_DECREF(m) would then be called one too many times.
There was a problem hiding this comment.
Some minor refactoring would be needed, but I don't think that's insurmountable (perhaps you can use Py_CLEAR instead).
| print("del sys.modules['__main__']", file=script) | ||
| assert_python_ok(filename) | ||
|
|
||
| def test_global_del_SystemExit(self): |
There was a problem hiding this comment.
I don't think test_cmd_line is the right place for this. test_gc already has related tests (see e.g. test_gc_main_module_at_shutdown() there).
|
@pitrou Thanks for the comments. I've updated the PR. |
|
Thanks @ZackerySpytz for the PR, and @pitrou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6. |
|
Thanks @ZackerySpytz for the PR, and @pitrou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7. |
|
Thanks @ZackerySpytz ! |
|
GH-8069 is a backport of this pull request to the 3.6 branch. |
…ythonGH-7918) PyErr_Print() will not return when the exception is a SystemExit, so decref the __main__ module object in that case. (cherry picked from commit d8cba5d) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
|
GH-8070 is a backport of this pull request to the 3.7 branch. |
…ythonGH-7918) PyErr_Print() will not return when the exception is a SystemExit, so decref the __main__ module object in that case. (cherry picked from commit d8cba5d) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
PyErr_Print() will not return when the exception is a SystemExit, so
decref the main module object in that case.
https://bugs.python.org/issue24596