zeth / inputs

Cross-platform Python support for keyboards, mice and gamepads
BSD 3-Clause "New" or "Revised" License
269 stars 87 forks source link

How to shutdown inputs? #92

Open u2ros opened 4 years ago

u2ros commented 4 years ago

Hi, i am running inputs in a python threading.Thread custom class. Therun methond looks like this:

while True:
    events = inputs.get_gamepad()
    #process events

Usually i shutdown a thread by using a running flag in the while loop, or, when using a threading.queue i send a None task which then breaks the loop on shutdown.

None of these methods is applicable here, since the run method only fires when events are rad from get_gamepad(). Any idea how to kill this thrad from another thread?

u2ros commented 4 years ago

Or should i say... get_gamepad() blocks...

vke-code commented 3 years ago

I too am having the same issue. I am starting two threads to monitor keyboard and mouse events. I am unable to .join() the threads after setting a shutdown flag as they are blocking on the read(). I have yet to find a flag or interrupt that can shutdown inputs cleanly.

def keyboard_handler(self): while self.run_keyboard_handler: events = self.keyboard.read() for event in events: self.process_event(event)