[Python-checkins] bpo-36368: Ignore SIGINT in SharedMemoryManager servers. (GH-12483)
Antoine Pitrou
webhook-mailer at python.org
Fri May 10 14:42:40 EDT 2019
https://github.com/python/cpython/commit/d0d64ad1f5f1dc1630004091d7f8209546c1220a
commit: d0d64ad1f5f1dc1630004091d7f8209546c1220a
branch: master
author: Pierre Glaser <pierreglaser at msn.com>
committer: Antoine Pitrou <antoine at python.org>
date: 2019年05月10日T20:42:35+02:00
summary:
bpo-36368: Ignore SIGINT in SharedMemoryManager servers. (GH-12483)
Fix a bug crashing SharedMemoryManager instances in interactive sessions after
a Ctrl-C (KeyboardInterrupt) was sent.
files:
A Misc/NEWS.d/next/Library/2019-03-21-16-00-00.bpo-36368.zsRT1.rst
M Lib/multiprocessing/managers.py
M Lib/test/_test_multiprocessing.py
diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py
index 22abd47fb1f2..2bad636855fe 100644
--- a/Lib/multiprocessing/managers.py
+++ b/Lib/multiprocessing/managers.py
@@ -17,6 +17,7 @@
import sys
import threading
+import signal
import array
import queue
import time
@@ -596,6 +597,9 @@ def _run_server(cls, registry, address, authkey, serializer, writer,
'''
Create a server, report its address and run it
'''
+ # bpo-36368: protect server process from KeyboardInterrupt signals
+ signal.signal(signal.SIGINT, signal.SIG_IGN)
+
if initializer is not None:
initializer(*initargs)
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index 836fde88cd26..d97e4232f7ac 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -3734,6 +3734,30 @@ def test_shared_memory_across_processes(self):
sms.close()
+ @unittest.skipIf(os.name != "posix", "not feasible in non-posix platforms")
+ def test_shared_memory_SharedMemoryServer_ignores_sigint(self):
+ # bpo-36368: protect SharedMemoryManager server process from
+ # KeyboardInterrupt signals.
+ smm = multiprocessing.managers.SharedMemoryManager()
+ smm.start()
+
+ # make sure the manager works properly at the beginning
+ sl = smm.ShareableList(range(10))
+
+ # the manager's server should ignore KeyboardInterrupt signals, and
+ # maintain its connection with the current process, and success when
+ # asked to deliver memory segments.
+ os.kill(smm._process.pid, signal.SIGINT)
+
+ sl2 = smm.ShareableList(range(10))
+
+ # test that the custom signal handler registered in the Manager does
+ # not affect signal handling in the parent process.
+ with self.assertRaises(KeyboardInterrupt):
+ os.kill(os.getpid(), signal.SIGINT)
+
+ smm.shutdown()
+
def test_shared_memory_SharedMemoryManager_basics(self):
smm1 = multiprocessing.managers.SharedMemoryManager()
with self.assertRaises(ValueError):
diff --git a/Misc/NEWS.d/next/Library/2019-03-21-16-00-00.bpo-36368.zsRT1.rst b/Misc/NEWS.d/next/Library/2019-03-21-16-00-00.bpo-36368.zsRT1.rst
new file mode 100644
index 000000000000..d8426827cedf
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-03-21-16-00-00.bpo-36368.zsRT1.rst
@@ -0,0 +1,2 @@
+Fix a bug crashing SharedMemoryManager instances in interactive sessions after
+a ctrl-c (KeyboardInterrupt) was sent
More information about the Python-checkins
mailing list