psss / rpms / python3

Forked from rpms/python3 5 years ago
Clone
b9f2533
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
b9f2533
index 492a84a2313..9746678607c 100644
b9f2533
--- a/Lib/test/test_asyncio/test_events.py
b9f2533
+++ b/Lib/test/test_asyncio/test_events.py
b9f2533
@@ -1980,19 +1980,26 @@ def test_subprocess_terminate(self):
b9f2533
 
b9f2533
     @unittest.skipIf(sys.platform == 'win32', "Don't have SIGHUP")
b9f2533
     def test_subprocess_send_signal(self):
b9f2533
-        prog = os.path.join(os.path.dirname(__file__), 'echo.py')
b9f2533
-
b9f2533
-        connect = self.loop.subprocess_exec(
b9f2533
-                        functools.partial(MySubprocessProtocol, self.loop),
b9f2533
-                        sys.executable, prog)
b9f2533
-        transp, proto = self.loop.run_until_complete(connect)
b9f2533
-        self.assertIsInstance(proto, MySubprocessProtocol)
b9f2533
-        self.loop.run_until_complete(proto.connected)
b9f2533
-
b9f2533
-        transp.send_signal(signal.SIGHUP)
b9f2533
-        self.loop.run_until_complete(proto.completed)
b9f2533
-        self.assertEqual(-signal.SIGHUP, proto.returncode)
b9f2533
-        transp.close()
b9f2533
+        # bpo-31034: Make sure that we get the default signal handler (killing
b9f2533
+        # the process). The parent process may have decided to ignore SIGHUP,
b9f2533
+        # and signal handlers are inherited.
b9f2533
+        old_handler = signal.signal(signal.SIGHUP, signal.SIG_DFL)
b9f2533
+        try:
b9f2533
+            prog = os.path.join(os.path.dirname(__file__), 'echo.py')
b9f2533
+
b9f2533
+            connect = self.loop.subprocess_exec(
b9f2533
+                            functools.partial(MySubprocessProtocol, self.loop),
b9f2533
+                            sys.executable, prog)
b9f2533
+            transp, proto = self.loop.run_until_complete(connect)
b9f2533
+            self.assertIsInstance(proto, MySubprocessProtocol)
b9f2533
+            self.loop.run_until_complete(proto.connected)
b9f2533
+
b9f2533
+            transp.send_signal(signal.SIGHUP)
b9f2533
+            self.loop.run_until_complete(proto.completed)
b9f2533
+            self.assertEqual(-signal.SIGHUP, proto.returncode)
b9f2533
+            transp.close()
b9f2533
+        finally:
b9f2533
+            signal.signal(signal.SIGHUP, old_handler)
b9f2533
 
b9f2533
     def test_subprocess_stderr(self):
b9f2533
         prog = os.path.join(os.path.dirname(__file__), 'echo2.py')
b9f2533
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
b9f2533
index 2e14a8a9735..e8822c36698 100644
b9f2533
--- a/Lib/test/test_asyncio/test_subprocess.py
b9f2533
+++ b/Lib/test/test_asyncio/test_subprocess.py
b9f2533
@@ -166,25 +166,32 @@ def test_terminate(self):
b9f2533
 
b9f2533
     @unittest.skipIf(sys.platform == 'win32', "Don't have SIGHUP")
b9f2533
     def test_send_signal(self):
b9f2533
-        code = 'import time; print("sleeping", flush=True); time.sleep(3600)'
b9f2533
-        args = [sys.executable, '-c', code]
b9f2533
-        create = asyncio.create_subprocess_exec(*args,
b9f2533
-                                                stdout=subprocess.PIPE,
b9f2533
-                                                loop=self.loop)
b9f2533
-        proc = self.loop.run_until_complete(create)
b9f2533
-
b9f2533
-        @asyncio.coroutine
b9f2533
-        def send_signal(proc):
b9f2533
-            # basic synchronization to wait until the program is sleeping
b9f2533
-            line = yield from proc.stdout.readline()
b9f2533
-            self.assertEqual(line, b'sleeping\n')
b9f2533
+        # bpo-31034: Make sure that we get the default signal handler (killing
b9f2533
+        # the process). The parent process may have decided to ignore SIGHUP,
b9f2533
+        # and signal handlers are inherited.
b9f2533
+        old_handler = signal.signal(signal.SIGHUP, signal.SIG_DFL)
b9f2533
+        try:
b9f2533
+            code = 'import time; print("sleeping", flush=True); time.sleep(3600)'
b9f2533
+            args = [sys.executable, '-c', code]
b9f2533
+            create = asyncio.create_subprocess_exec(*args,
b9f2533
+                                                    stdout=subprocess.PIPE,
b9f2533
+                                                    loop=self.loop)
b9f2533
+            proc = self.loop.run_until_complete(create)
b9f2533
 
b9f2533
-            proc.send_signal(signal.SIGHUP)
b9f2533
-            returncode = (yield from proc.wait())
b9f2533
-            return returncode
b9f2533
-
b9f2533
-        returncode = self.loop.run_until_complete(send_signal(proc))
b9f2533
-        self.assertEqual(-signal.SIGHUP, returncode)
b9f2533
+            @asyncio.coroutine
b9f2533
+            def send_signal(proc):
b9f2533
+                # basic synchronization to wait until the program is sleeping
b9f2533
+                line = yield from proc.stdout.readline()
b9f2533
+                self.assertEqual(line, b'sleeping\n')
b9f2533
+
b9f2533
+                proc.send_signal(signal.SIGHUP)
b9f2533
+                returncode = (yield from proc.wait())
b9f2533
+                return returncode
b9f2533
+
b9f2533
+            returncode = self.loop.run_until_complete(send_signal(proc))
b9f2533
+            self.assertEqual(-signal.SIGHUP, returncode)
b9f2533
+        finally:
b9f2533
+            signal.signal(signal.SIGHUP, old_handler)
b9f2533
 
b9f2533
     def prepare_broken_pipe_test(self):
b9f2533
         # buffer large enough to feed the whole pipe buffer