Andrew Moffat added the comment:

If I move tcsetattr into the parent, the race condition still exists.  If I 
move it into the child, before the write(), it works.

My environment is OSX 10.7.2 inside of Virtualbox (maybe this is the problem?)

I've shuffled some code around, and found case that fails consistently in 
python 3, but succeeds consistently on python 2.7.  It doesn't use tcsetattr at 
all, which is making me realize the problem may be deeper than I originally 
thought.  Are you able to confirm this, Ned?


import os
import pty
import resource
import signal
import tty
import time


master, slave = pty.openpty()
pid = os.fork()



# 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:
    time.sleep(0.5)
    os.close(slave)

    try:
        print(os.read(master, 1024))

    finally:
        os.kill(pid, signal.SIGKILL)

----------

_______________________________________
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

Reply via email to