mirror of
https://github.com/python/cpython.git
synced 2025-09-12 11:46:52 +00:00
[3.13] gh-127586: multiprocessing.Pool does not properly restore blocked signals (try 2) (GH-128011) (#128298)
gh-127586: multiprocessing.Pool does not properly restore blocked signals (try 2) (GH-128011)
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.
(cherry picked from commit aeb9b65aa2
)
Co-authored-by: Stephen Hansen <stephen.paul.hansen@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
This commit is contained in:
parent
aea2e03b27
commit
16fde763e5
3 changed files with 28 additions and 3 deletions
|
@ -5950,6 +5950,27 @@ class TestResourceTracker(unittest.TestCase):
|
|||
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
|
||||
orig_sigmask = signal.pthread_sigmask(signal.SIG_BLOCK, set())
|
||||
signals = {signal.SIGTERM, signal.SIGINT, signal.SIGUSR1}
|
||||
|
||||
try:
|
||||
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()
|
||||
finally:
|
||||
# restore sigmask to what it was before executing test
|
||||
signal.pthread_sigmask(signal.SIG_SETMASK, orig_sigmask)
|
||||
|
||||
class TestSimpleQueue(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue