-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Characters sometimes (rarely) echoed when using getchar #435
Comments
Please also note that this does not happen with this code: import os
import sys
import tty
f = open('/dev/tty')
fd = f.fileno()
tty.setraw(fd)
ESC = '\x1b'
i = 0
while True:
c = os.read(fd, 32)
#print(c.decode("utf-8"))
i += 1
if c.decode("utf-8") == ESC:
print("total characters typed:", i)
exit() Please forgive the crappy example. You will have to |
It seems it's impossible to fix this race condition without breaking the API. |
Thanks for the quick reply. Do you know what exactly is causing this behaviour? Am I correct with the assumption that |
Yes exactly, but "making it fast enough" is not a good fix. As said in the other issue, |
So introducing something like a function to enable/disable a "raw state" for the length of the desired getchar capture would fix this problem? Do you think that could work without breaking the API? |
Well, if you want to use Right now you'd write:
To avoid this bug, you'd write:
I don't think a bugfix that only changes code in Click is possible. |
Allright, I'll use the solution you suggested over at the other issue for now and maybe look into the details here later if I have some time. Should we close this issue as not fixable in the meantime? |
Let's keep this open. |
@untitaker One more question: Is it intended behaviour that the echo function does only produce a newline and no carriage return? Because this leads to this problem when echoing in raw mode, so it's not possible to stay in raw mode while using echo. Would it break anything to add |
That's definetly intentional. Sending \r looks like a workaround to me. Please open a new issue for that if you think that's an issue Click should be On Sat, Oct 10, 2015 at 02:53:12PM -0700, Stefan wrote:
|
Fixed this in #1007 |
Please consider the following example:
(Press ESC to exit when running it)
When I run this in
gnome-terminal
underLinux User 3.13.0-37-generic #64-Ubuntu x86_64 x86_64 x86_64 GNU/Linux
and randomly smash on the keyboard, the output is similar to the following:I am actually trying to solve this bug in case anyone is wondering why I am smashing on my keyboard ;)
So the problem is that a handful of characters gets printed instead of being catched by getchar(). I also suspect this is because of the nearly simultaneous key presses.
Does anyone know a solution to this problem?
The text was updated successfully, but these errors were encountered: