mirror of
https://github.com/python/cpython.git
synced 2025-10-05 22:51:56 +00:00
* bpo-31034: Reliable signal handler for test_asyncio
Don't rely on the current SIGHUP signal handler, make sure that it's
set to the "default" signal handler: SIG_DFL.
* Add comments
(cherry picked from commit 830080913c
)
This commit is contained in:
parent
59e6ab15e4
commit
efe9fcbd2c
2 changed files with 41 additions and 27 deletions
|
@ -1980,19 +1980,26 @@ class SubprocessTestsMixin:
|
|||
|
||||
@unittest.skipIf(sys.platform == 'win32', "Don't have SIGHUP")
|
||||
def test_subprocess_send_signal(self):
|
||||
prog = os.path.join(os.path.dirname(__file__), 'echo.py')
|
||||
# bpo-31034: Make sure that we get the default signal handler (killing
|
||||
# the process). The parent process may have decided to ignore SIGHUP,
|
||||
# and signal handlers are inherited.
|
||||
old_handler = signal.signal(signal.SIGHUP, signal.SIG_DFL)
|
||||
try:
|
||||
prog = os.path.join(os.path.dirname(__file__), 'echo.py')
|
||||
|
||||
connect = self.loop.subprocess_exec(
|
||||
functools.partial(MySubprocessProtocol, self.loop),
|
||||
sys.executable, prog)
|
||||
transp, proto = self.loop.run_until_complete(connect)
|
||||
self.assertIsInstance(proto, MySubprocessProtocol)
|
||||
self.loop.run_until_complete(proto.connected)
|
||||
connect = self.loop.subprocess_exec(
|
||||
functools.partial(MySubprocessProtocol, self.loop),
|
||||
sys.executable, prog)
|
||||
transp, proto = self.loop.run_until_complete(connect)
|
||||
self.assertIsInstance(proto, MySubprocessProtocol)
|
||||
self.loop.run_until_complete(proto.connected)
|
||||
|
||||
transp.send_signal(signal.SIGHUP)
|
||||
self.loop.run_until_complete(proto.completed)
|
||||
self.assertEqual(-signal.SIGHUP, proto.returncode)
|
||||
transp.close()
|
||||
transp.send_signal(signal.SIGHUP)
|
||||
self.loop.run_until_complete(proto.completed)
|
||||
self.assertEqual(-signal.SIGHUP, proto.returncode)
|
||||
transp.close()
|
||||
finally:
|
||||
signal.signal(signal.SIGHUP, old_handler)
|
||||
|
||||
def test_subprocess_stderr(self):
|
||||
prog = os.path.join(os.path.dirname(__file__), 'echo2.py')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue