diff options
author | Stephen Hansen <stephen.paul.hansen@gmail.com> | 2024-12-27 17:09:01 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-27 14:09:01 -0800 |
commit | aeb9b65aa26444529e4adc7d6e5b0d3dd9889ec2 (patch) | |
tree | 40cced63f9b0dd96af9949ac47a0e131d26aca4a /Lib/multiprocessing/resource_tracker.py | |
parent | 64173cd6f2d8dc95c6f8b67912d0edd1c1b707d5 (diff) | |
download | cpython-aeb9b65aa26444529e4adc7d6e5b0d3dd9889ec2.tar.gz cpython-aeb9b65aa26444529e4adc7d6e5b0d3dd9889ec2.zip |
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.
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib/multiprocessing/resource_tracker.py')
-rw-r--r-- | Lib/multiprocessing/resource_tracker.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/multiprocessing/resource_tracker.py b/Lib/multiprocessing/resource_tracker.py index 20ddd9c50e3..90e036ae905 100644 --- a/Lib/multiprocessing/resource_tracker.py +++ b/Lib/multiprocessing/resource_tracker.py @@ -155,13 +155,14 @@ class ResourceTracker(object): # that can make the child die before it registers signal handlers # for SIGINT and SIGTERM. The mask is unregistered after spawning # the child. + prev_sigmask = None try: if _HAVE_SIGMASK: - signal.pthread_sigmask(signal.SIG_BLOCK, _IGNORED_SIGNALS) + prev_sigmask = signal.pthread_sigmask(signal.SIG_BLOCK, _IGNORED_SIGNALS) pid = util.spawnv_passfds(exe, args, fds_to_pass) finally: - if _HAVE_SIGMASK: - signal.pthread_sigmask(signal.SIG_UNBLOCK, _IGNORED_SIGNALS) + if prev_sigmask is not None: + signal.pthread_sigmask(signal.SIG_SETMASK, prev_sigmask) except: os.close(w) raise |