inputs
inputs copied to clipboard
Clean exit - BrokenPipeError
OS: Windows 10 Python: 3.6
Is there a way to have a clean exit from a program that uses the library Inputs? I exit the while loop when the key ESC is pressed. However, the program does not terminate. If I press CTRL+C, the program does not terminate (s. image). I even tried to attach a window to the main program (a pygame window) that when closed terminates it. It seems to work at first glance, but if I press any keyboard key after closing that window I get a BrokenPipeError (s. image). Any ideas?
That is a good question. We need to not only exit on KeyboardInterrupt but also give a method for programs using inputs to kill the subprocess.
A workaround for now is that Ctrl+Break ends the current process on Windows. I had to actually add an external keyboard because my Windows machine doesn't have a break key.
I have this problem on my windows 10 machine as well. Is there some way to call a function to exit?
This is what happens when I do ctrl+c: Traceback (most recent call last): File "_ctypes/callbacks.c", line 234, in 'calling callback function' File "C:\python35\lib\site-packages\inputs.py", line 1670, in handle_input def handle_input(self, ncode, wparam, lparam): KeyboardInterrupt
the ctrl+break works for me, (it's fn+b on my Lenovo). sys.exit() does the same as break
This looks like a threading issue. The thread listening to keyboard input needs to be made a daemon thread so when the main thread exits, the daemon thread exits as well.
Is there any way of simulating input with inputs?
I don't think this is a Design idea, it is a bug. I can't bundle inputs into my app until I can clean exit out of an app. It's the only thing keeping me from using inputs in my app right now. I'm experimenting with different ways of exiting out of the Processes, but I've always used threading and need to figure out how Pipe works and where all the threads are.
I'm running into the same issue. This module is perfect for my application except that I can't get it to exit cleanly, which is sometimes important. Are there any updates or a better work-around for this issue?