New submission from Andrew Moffat: I'm getting some kind of race condition on OSX when trying to read the output from a pseudoterminal of a forked process. This race conditional only occurs if I run tty.tcsetattr on the master side of the pty, regardless of if I actually change the mode or not.
Try running the following code on OSX multiple times. Sometimes you'll see "testing", sometimes you won't, sometimes it hangs. If you comment out "tty.tcsetattr", you will consistently see "testing". import os import pty import resource import signal import tty master, slave = pty.openpty() pid = os.fork() # BUG IS HERE # we're not making any changes to the tty mode, but # the mere act of setting a mode causes the output to only # show up sometimes. # # comment out "tty.tcsetattr" and the bug goes away mode = tty.tcgetattr(master) tty.tcsetattr(master, tty.TCSANOW, mode) # child process if pid == 0: os.setsid() os.close(master) os.dup2(slave, 0) os.dup2(slave, 1) os.dup2(slave, 2) max_fd = resource.getrlimit(resource.RLIMIT_NOFILE)[0] os.closerange(3, max_fd) # make controlling terminal. taken from pty.fork tmp_fd = os.open(os.ttyname(1), os.O_RDWR) os.close(tmp_fd) os.write(1, "testing".encode()) os._exit(255) # parent process else: os.close(slave) try: print(os.read(master, 1024)) finally: os.kill(pid, signal.SIGKILL) ---------- messages: 170147 nosy: amoffat priority: normal severity: normal status: open title: OSX TTY bug type: behavior versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue15898> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com