(self)
| 195 | |
| 196 | @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 197 | def test_fork(self): |
| 198 | debug("calling pty.fork()") |
| 199 | pid, master_fd = pty.fork() |
| 200 | self.addCleanup(os.close, master_fd) |
| 201 | if pid == pty.CHILD: |
| 202 | # stdout should be connected to a tty. |
| 203 | if not os.isatty(1): |
| 204 | debug("Child's fd 1 is not a tty?!") |
| 205 | os._exit(3) |
| 206 | |
| 207 | # After pty.fork(), the child should already be a session leader. |
| 208 | # (on those systems that have that concept.) |
| 209 | debug("In child, calling os.setsid()") |
| 210 | try: |
| 211 | os.setsid() |
| 212 | except OSError: |
| 213 | # Good, we already were session leader |
| 214 | debug("Good: OSError was raised.") |
| 215 | pass |
| 216 | except AttributeError: |
| 217 | # Have pty, but not setsid()? |
| 218 | debug("No setsid() available?") |
| 219 | pass |
| 220 | except: |
| 221 | # We don't want this error to propagate, escaping the call to |
| 222 | # os._exit() and causing very peculiar behavior in the calling |
| 223 | # regrtest.py ! |
| 224 | # Note: could add traceback printing here. |
| 225 | debug("An unexpected error was raised.") |
| 226 | os._exit(1) |
| 227 | else: |
| 228 | debug("os.setsid() succeeded! (bad!)") |
| 229 | os._exit(2) |
| 230 | os._exit(4) |
| 231 | else: |
| 232 | self.assertFalse(os.get_inheritable(master_fd)) |
| 233 | debug("Waiting for child (%d) to finish." % pid) |
| 234 | # In verbose mode, we have to consume the debug output from the |
| 235 | # child or the child will block, causing this test to hang in the |
| 236 | # parent's waitpid() call. The child blocks after a |
| 237 | # platform-dependent amount of data is written to its fd. On |
| 238 | # Linux 2.6, it's 4000 bytes and the child won't block, but on OS |
| 239 | # X even the small writes in the child above will block it. Also |
| 240 | # on Linux, the read() will raise an OSError (input/output error) |
| 241 | # when it tries to read past the end of the buffer but the child's |
| 242 | # already exited, so catch and discard those exceptions. It's not |
| 243 | # worth checking for EIO. |
| 244 | while True: |
| 245 | try: |
| 246 | data = os.read(master_fd, 80) |
| 247 | except OSError: |
| 248 | break |
| 249 | if not data: |
| 250 | break |
| 251 | sys.stdout.write(str(data.replace(b'\r\n', b'\n'), |
| 252 | encoding='ascii')) |
| 253 | |
| 254 | ##line = os.read(master_fd, 80) |
nothing calls this directly
no test coverage detected