bpo-31160: test_tempfile: Fix reap_children() warning (#3056) · python/cpython@6c8c294 (original) (raw)

`@@ -78,7 +78,6 @@ def setUp(self):

`

78

78

`def tearDown(self):

`

79

79

`self._warnings_manager.exit(None, None, None)

`

80

80

``

81

``

-

82

81

`def nameCheck(self, name, dir, pre, suf):

`

83

82

` (ndir, nbase) = os.path.split(name)

`

84

83

`npre = nbase[:len(pre)]

`

`@@ -184,12 +183,15 @@ def test_process_awareness(self):

`

184

183

`try:

`

185

184

`pid = os.fork()

`

186

185

`if not pid:

`

``

186

`+

child process

`

187

187

`os.close(read_fd)

`

188

188

`os.write(write_fd, next(self.r).encode("ascii"))

`

189

189

`os.close(write_fd)

`

190

190

`# bypass the normal exit handlers- leave those to

`

191

191

`# the parent.

`

192

192

`os._exit(0)

`

``

193

+

``

194

`+

parent process

`

193

195

`parent_value = next(self.r)

`

194

196

`child_value = os.read(read_fd, len(parent_value)).decode("ascii")

`

195

197

`finally:

`

`@@ -200,6 +202,10 @@ def test_process_awareness(self):

`

200

202

`os.kill(pid, signal.SIGKILL)

`

201

203

`except OSError:

`

202

204

`pass

`

``

205

+

``

206

`+

Read the process exit status to avoid zombie process

`

``

207

`+

os.waitpid(pid, 0)

`

``

208

+

203

209

`os.close(read_fd)

`

204

210

`os.close(write_fd)

`

205

211

`self.assertNotEqual(child_value, parent_value)

`