moses-palmer / pynput

Sends virtual input commands
GNU Lesser General Public License v3.0
1.77k stars 245 forks source link

timeout in Listener.join() doesn't work #467

Closed mseifrid closed 2 years ago

mseifrid commented 2 years ago

Description When setting a timeout for the Listener.join() method, Listener doesn't stop after the timeout time. From some debugging, looks like the issue is that the join method gets stuck on on exc_type, exc_value, exc_traceback = self._queue.get() (line 273 of pynput/_ util/ init .py) indefinitely.

Platform and pynput version OS: macOS 11.6.5, Ubuntu 20.04, Windows 10 Python: 3.9 pynput: 1.7.6

To Reproduce

def on_press(key):
    print(key)

def on_release(key):
    if key == keyboard.Key.space:
        print(key)
        # Stop listener
        return False

with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
    listener.join(1)
moses-palmer commented 2 years ago

Thank you for your report and keen observation.

I have updated the master branch with a fix for this issue.