mitsuhiko/teetty

stdout/stderr desync in script mode

mitsuhiko opened this issue · 1 comments

Today stderr and stdout end up highly desynchronized if they are used in script mode. I believe that this is generally an unsolvable issue however faketty does not appear to have this issue despite it having separate streams. I believe that the fact that stderr appears as a tty there changes something in how tools print.

I tried to swap out pipe() with openpty() for script mode but by itself that doesn't do anything. I think the main reason why faketty appears to be able to synchronize the streams is that it doesn't do any select() or similar. Hooking some debug prints in, the two lines from stdout appear in the same flush as the one line from stderr in my test script. I think if I were not to select but have a separate thread to try to funnel stdout to stdout and stderr to stderr as quickly as possible they might appear synchronized. I am however not sure that this is going to reliably fix the issue.