| 193 | |
| 194 | @support.requires_fork() |
| 195 | def test_process_awareness(self): |
| 196 | # ensure that the random source differs between |
| 197 | # child and parent. |
| 198 | read_fd, write_fd = os.pipe() |
| 199 | pid = None |
| 200 | try: |
| 201 | pid = os.fork() |
| 202 | if not pid: |
| 203 | # child process |
| 204 | os.close(read_fd) |
| 205 | os.write(write_fd, next(self.r).encode("ascii")) |
| 206 | os.close(write_fd) |
| 207 | # bypass the normal exit handlers- leave those to |
| 208 | # the parent. |
| 209 | os._exit(0) |
| 210 | |
| 211 | # parent process |
| 212 | parent_value = next(self.r) |
| 213 | child_value = os.read(read_fd, len(parent_value)).decode("ascii") |
| 214 | finally: |
| 215 | if pid: |
| 216 | support.wait_process(pid, exitcode=0) |
| 217 | |
| 218 | os.close(read_fd) |
| 219 | os.close(write_fd) |
| 220 | self.assertNotEqual(child_value, parent_value) |
| 221 | |
| 222 | |
| 223 | |