diff options
author | Stephen Hansen <stephen.paul.hansen@gmail.com> | 2024-12-15 14:53:22 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-15 11:53:22 -0800 |
commit | 46006a1b355f75d06c10e7b8086912c483b34487 (patch) | |
tree | 03efaaf9e69c71002d4babf7e76e028a5a406f80 /Lib/test/_test_multiprocessing.py | |
parent | 7b8bd3b2b81f4aca63c5b603b56998f6b3ee2611 (diff) | |
download | cpython-46006a1b355f75d06c10e7b8086912c483b34487.tar.gz cpython-46006a1b355f75d06c10e7b8086912c483b34487.zip |
gh-127586: properly restore blocked signals in resource_tracker.py (GH-127587)
* Correct pthread_sigmask in resource_tracker to restore old signals
Using SIG_UNBLOCK to remove blocked "ignored signals" may accidentally
cause side effects if the calling parent already had said signals
blocked to begin with and did not intend to unblock them when
creating a pool. Use SIG_SETMASK instead with the previous mask of
blocked signals to restore the original blocked set.
* Adding resource_tracker blocked signals test
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib/test/_test_multiprocessing.py')
-rw-r--r-- | Lib/test/_test_multiprocessing.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index 80b08b8ac66..01e92f0d8d6 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -6044,6 +6044,21 @@ class TestResourceTracker(unittest.TestCase): self._test_resource_tracker_leak_resources( cleanup=cleanup, ) + @unittest.skipUnless(hasattr(signal, "pthread_sigmask"), "pthread_sigmask is not available") + def test_resource_tracker_blocked_signals(self): + # + # gh-127586: Check that resource_tracker does not override blocked signals of caller. + # + from multiprocessing.resource_tracker import ResourceTracker + signals = {signal.SIGTERM, signal.SIGINT, signal.SIGUSR1} + + for sig in signals: + signal.pthread_sigmask(signal.SIG_SETMASK, {sig}) + self.assertEqual(signal.pthread_sigmask(signal.SIG_BLOCK, set()), {sig}) + tracker = ResourceTracker() + tracker.ensure_running() + self.assertEqual(signal.pthread_sigmask(signal.SIG_BLOCK, set()), {sig}) + tracker._stop() class TestSimpleQueue(unittest.TestCase): |