bpo-31034: Reliable signal handler for test_asyncio (#2867) · python/cpython@8300809 (original) (raw)

`@@ -166,25 +166,32 @@ def test_terminate(self):

`

166

166

``

167

167

`@unittest.skipIf(sys.platform == 'win32', "Don't have SIGHUP")

`

168

168

`def test_send_signal(self):

`

169

``

`-

code = 'import time; print("sleeping", flush=True); time.sleep(3600)'

`

170

``

`-

args = [sys.executable, '-c', code]

`

171

``

`-

create = asyncio.create_subprocess_exec(*args,

`

172

``

`-

stdout=subprocess.PIPE,

`

173

``

`-

loop=self.loop)

`

174

``

`-

proc = self.loop.run_until_complete(create)

`

175

``

-

176

``

`-

@asyncio.coroutine

`

177

``

`-

def send_signal(proc):

`

178

``

`-

basic synchronization to wait until the program is sleeping

`

179

``

`-

line = yield from proc.stdout.readline()

`

180

``

`-

self.assertEqual(line, b'sleeping\n')

`

``

169

`+

bpo-31034: Make sure that we get the default signal handler (killing

`

``

170

`+

the process). The parent process may have decided to ignore SIGHUP,

`

``

171

`+

and signal handlers are inherited.

`

``

172

`+

old_handler = signal.signal(signal.SIGHUP, signal.SIG_DFL)

`

``

173

`+

try:

`

``

174

`+

code = 'import time; print("sleeping", flush=True); time.sleep(3600)'

`

``

175

`+

args = [sys.executable, '-c', code]

`

``

176

`+

create = asyncio.create_subprocess_exec(*args,

`

``

177

`+

stdout=subprocess.PIPE,

`

``

178

`+

loop=self.loop)

`

``

179

`+

proc = self.loop.run_until_complete(create)

`

181

180

``

182

``

`-

proc.send_signal(signal.SIGHUP)

`

183

``

`-

returncode = (yield from proc.wait())

`

184

``

`-

return returncode

`

185

``

-

186

``

`-

returncode = self.loop.run_until_complete(send_signal(proc))

`

187

``

`-

self.assertEqual(-signal.SIGHUP, returncode)

`

``

181

`+

@asyncio.coroutine

`

``

182

`+

def send_signal(proc):

`

``

183

`+

basic synchronization to wait until the program is sleeping

`

``

184

`+

line = yield from proc.stdout.readline()

`

``

185

`+

self.assertEqual(line, b'sleeping\n')

`

``

186

+

``

187

`+

proc.send_signal(signal.SIGHUP)

`

``

188

`+

returncode = (yield from proc.wait())

`

``

189

`+

return returncode

`

``

190

+

``

191

`+

returncode = self.loop.run_until_complete(send_signal(proc))

`

``

192

`+

self.assertEqual(-signal.SIGHUP, returncode)

`

``

193

`+

finally:

`

``

194

`+

signal.signal(signal.SIGHUP, old_handler)

`

188

195

``

189

196

`def prepare_broken_pipe_test(self):

`

190

197

`# buffer large enough to feed the whole pipe buffer

`