-
Notifications
You must be signed in to change notification settings - Fork 732
patch_stdout corrupts terminal output if lots of output #681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
One weird thing I did notice is that I CTRL-C'ed once without patch_stdout and for some reason it looked like there were a lot of threads in auto_flush_input or key_processor.py wait. |
Thank you for reporting! A work-around for now could be to create a simple full-screen application, with a text area on top for all the output, and an input field at the bottom for the prompt. It'll take more code then this simple prompt, but that should work fine. I believe there is an example in the examples directory. |
I started originally with an application but I encountered a few stumbling blocks.
The first point is by far the biggest issue. |
So I looked into this a bit and it seems like the problem disappears if I comment out ask_cpr in vt100.py. Still not quite sure why it's causing corruption. Maybe it's somehow being accessed from 2 threads? |
Nope, doesn't appear to be a threading issue. Maybe response bytes from the CPR are being echoed somewhere for some reason? |
@vlovich you can see the discussion at #456, which was a similar issue (but already solved in 2.0). Basically, CPR requests are a bit weird with the way prompt-toolkit is designed because the input and output classes have to coordinate them. The output sends the request and it has to set the terminal to echo off while the input waits for it. If the response is sent when echo is on (due to a race condition, for instance), it is printed to the terminal. Given that you are using threads and spamming the input, a race condition seems likely here. |
Ah. That certainly seems like it's on the right track but I'm not sure I understand the internals enough for the explanation to make complete sense. The spam text from the background thread to the foreground happens within run_coroutine_in_terminal & thus should happen on the main thread. In fact, if you just change the background thread to write directly to stdout (without patch_stdout), then everything works more correctly. I'll try having patch_stdout check for pending CPR & attaching to the future's done callback instead if there is one. |
Run this example program on OSX 10.13.5 terminal & a bunch of garbage escaped escape codes are printed to the screen.
Example corruption pasted below. Sometimes the terminal will even output the bell sound which to me indicates this corruption also sometimes manifests as the escape codes being written raw to the terminal. I have been unable to track down where/how the escape codes/buffer corruption is coming in (looks fine AFAICT within the patch proxy).
The text was updated successfully, but these errors were encountered: