Message170147
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) |
|
Date |
User |
Action |
Args |
2012-09-10 00:58:14 | amoffat | set | recipients:
+ amoffat |
2012-09-10 00:58:14 | amoffat | set | messageid: <1347238694.31.0.649838162085.issue15898@psf.upfronthosting.co.za> |
2012-09-10 00:58:13 | amoffat | link | issue15898 messages |
2012-09-10 00:58:12 | amoffat | create | |
|