-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_signal module leak: test_interpreters leaked [1424, 1422, 1424] references #85879
Comments
AMD64 Fedora Rawhide Refleaks 3.x: test_interpreters leaked [1424, 1422, 1424] references, sum=4270 According to git bisect, the leak was introduced by: commit 71d1bd9
.../2020-09-01-17-07-20.bpo-1635741.7wSuCc.rst | 1 + Example of leak: $ ./python -m test -R 3:3 test_interpreters -m test.test_interpreters.TestInterpreterClose.test_from_current
0:00:00 load avg: 0.72 Run tests sequentially
0:00:00 load avg: 0.72 [1/1] test_interpreters
beginning 6 repetitions
123456
......
test_interpreters leaked [237, 237, 237] references, sum=711
test_interpreters leaked [18, 18, 18] memory blocks, sum=54
test_interpreters failed == Tests result: FAILURE == 1 test failed: Total duration: 1.1 sec |
The signal module is really special. In Python, only the main thread of the main interpreter is supposed to be allowed to run Python signal handlers (but the C signal handler can be executed by any thread). The exec function of the _signal module runs actions each time a new instance of the _signal module is created, whereas some actions must only be done exactly once:
For example, calling signal.signal() in a subinterpreter raises ValueError("signal only works in main thread of the main interpreter"). |
About the leak, the following three variables are also initialized multiple times by signal_exec(): static PyObject *DefaultHandler;
static PyObject *IgnoreHandler;
static PyObject *IntHandler; |
Another problem: PyOS_FiniInterrupts() is a public function of the C API which access global variables like IntHandler, DefaultHandler and IgnoreHandler. |
Sounds like there needs to be some python-wide global state that perhaps the signal module wraps rather than owns. I could try to prototype it if you agree |
Done! _signal uses again the multi-phase init API. |
The PyOS_InitInterrupts function is still listed in PC/python3dll.c. |
Petr Viktorin:
Ooops, I proposed PR 24257 to remove it. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: