inputs icon indicating copy to clipboard operation
inputs copied to clipboard

Clean exit - BrokenPipeError

Open miev88 opened this issue 6 years ago • 6 comments

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?

broken_pipe_error

miev88 avatar Mar 01 '18 09:03 miev88

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.

zeth avatar Jul 21 '18 18:07 zeth

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.

zeth avatar Jul 21 '18 19:07 zeth

I have this problem on my windows 10 machine as well. Is there some way to call a function to exit?

frastlin avatar Dec 01 '18 16:12 frastlin

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?

frastlin avatar Dec 01 '18 22:12 frastlin

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.

frastlin avatar Dec 02 '18 19:12 frastlin

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?

sarain avatar May 17 '20 09:05 sarain