Skip to content

Commit a0fe561

Browse files
author
Stephen Hansen
committed
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.
1 parent bfb0788 commit a0fe561

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Lib/multiprocessing/resource_tracker.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,14 @@ def ensure_running(self):
155155
# that can make the child die before it registers signal handlers
156156
# for SIGINT and SIGTERM. The mask is unregistered after spawning
157157
# the child.
158+
prev_sigmask = None
158159
try:
159160
if _HAVE_SIGMASK:
160-
signal.pthread_sigmask(signal.SIG_BLOCK, _IGNORED_SIGNALS)
161+
prev_sigmask = signal.pthread_sigmask(signal.SIG_BLOCK, _IGNORED_SIGNALS)
161162
pid = util.spawnv_passfds(exe, args, fds_to_pass)
162163
finally:
163-
if _HAVE_SIGMASK:
164-
signal.pthread_sigmask(signal.SIG_UNBLOCK, _IGNORED_SIGNALS)
164+
if prev_sigmask is not None:
165+
signal.pthread_sigmask(signal.SIG_SETMASK, prev_sigmask)
165166
except:
166167
os.close(w)
167168
raise

0 commit comments

Comments
 (0)