chrippa / ds4drv

A Sony DualShock 4 userspace driver for Linux
MIT License
1.05k stars 213 forks source link

Clean exit on SIGINT? #124

Open joseph-norman opened 7 years ago

joseph-norman commented 7 years ago

Hi guys,

Love the work you've done with this - works perfectly on my Ubuntu machine! Would you guys be interested in a PR that exited cleanly (i.e, without a stack trace) on a SIGINT in an active terminal? This gets a bit cumbersome when I'm running it:

^CTraceback (most recent call last):
  File "/usr/local/bin/ds4drv", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/ds4drv/__main__.py", line 154, in main
    for device in backend.devices:
  File "/usr/local/lib/python2.7/dist-packages/ds4drv/backends/hidraw.py", line 148, in devices
    for hidraw_device in itertools.chain(existing_devices, future_devices):
  File "/usr/local/lib/python2.7/dist-packages/ds4drv/backends/hidraw.py", line 127, in _get_future_devices
    for device in iter(monitor.poll, None):
  File "/usr/local/lib/python2.7/dist-packages/pyudev/monitor.py", line 357, in poll
    if eintr_retry_call(poll.Poll.for_events((self, 'r')).poll, timeout):
  File "/usr/local/lib/python2.7/dist-packages/pyudev/_util.py", line 163, in eintr_retry_call
    return func(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pyudev/_os/poll.py", line 97, in poll
    return list(self._parse_events(eintr_retry_call(self._notifier.poll, timeout)))
  File "/usr/local/lib/python2.7/dist-packages/pyudev/_util.py", line 163, in eintr_retry_call
    return func(*args, **kwargs)
KeyboardInterrupt

Cheers!

Ape commented 7 years ago

This should already work correctly. Here's an example output for me:

[info][controller 1] Created devices /dev/input/js0 (joystick) /dev/input/event19 (evdev) 
[info][controller 1] Connected to Bluetooth Controller (1C:66:6D:1A:6F:A0 hidraw2)
[info][hidraw] Scanning for devices
[info][controller 1] Battery: Fully charged
^C[info][controller 1] Disconnected
[info][controller 1] Cleaning up...
Ape commented 7 years ago

Does this only occur rarely for you? Can you try if Python 3 changes anything?

joseph-norman commented 7 years ago

I'll give Python 3 a try out - it occurs every time I close

Ciruxx commented 5 years ago

Same here with Arch Linux and Python 3.7.3!