New GitHub issue #110844 from PERFACCT-JS:<br>

<hr>

<pre>
The `ResourceTracker‎` class registers a signal mask during initialization, but does not correctly restore its previous state. The relevant code is shown here:
https://github.com/python/cpython/blob/b2ab210aaefb3b0e39f28e7946b7a531d7b2ab17/Lib/multiprocessing/resource_tracker.py#L145-L151

In [line 151](https://github.com/python/cpython/blob/b2ab210aaefb3b0e39f28e7946b7a531d7b2ab17/Lib/multiprocessing/resource_tracker.py#L151) signals `SIGINT` and `SIGTERM` will be unblocked unconditionally. Shouldn't it restore the signal mask that was active before?

The observed behavior can be demonstrated with the following simple example:
```python
import signal
import time
from multiprocessing.shared_memory import SharedMemory

# Ignore SIGINT signals from here on.
signal.pthread_sigmask(signal.SIG_BLOCK, {signal.SIGINT})

try:
    # Do some multi-processing stuff.
    shm = SharedMemory(create=True, size=8)

    # Simulate program execution. Pressing Ctrl-C within the next 60 seconds
    # should not interrupt the application.
    time.sleep(60)

finally:
    shm.close()
    shm.unlink()
```
The application will be interrupted when Ctrl-C is pressed, even though the code explicitly specifies to block the `SIGINT` signal. This is because the creation of `SharedMemory` invokes the `ResourceTracker‎`, which in turn removes `SIGINT` from the set of blocked signals.
</pre>

<hr>

<a href="https://github.com/python/cpython/issues/110844">View on GitHub</a>
<p>Labels: </p>
<p>Assignee: </p>