diff --git a/lib/hidapi/udev.py b/lib/hidapi/udev.py index 54823b68..f991eb1c 100644 --- a/lib/hidapi/udev.py +++ b/lib/hidapi/udev.py @@ -121,27 +121,44 @@ def monitor_async(callback, *device_filters): def monitor(callback, *device_filters): - c = _Context() + def _monitor(): + c = _Context() - for device in c.list_devices(subsystem='hidraw'): - # print (device, dict(device), dict(device.attributes)) - for filter in device_filters: - d_info = _match('add', device, *filter) - if d_info: - callback('add', d_info) - break - - m = _Monitor.from_netlink(c) - m.filter_by(subsystem='hidraw') - for action, device in m: - # print ('----', action, device) - if action in ('add', 'remove'): + for device in c.list_devices(subsystem='hidraw'): + # print (device, dict(device), dict(device.attributes)) for filter in device_filters: - d_info = _match(action, device, *filter) + d_info = _match('add', device, *filter) if d_info: - callback(action, d_info) + callback('add', d_info) break + m = _Monitor.from_netlink(c) + del c + + m.filter_by(subsystem='hidraw') + try: + for action, device in m: + # print ('----', action, device) + if action in ('add', 'remove'): + for filter in device_filters: + d_info = _match(action, device, *filter) + if d_info: + callback(action, d_info) + break + finally: + del m + + while True: + try: + _monitor() + except IOError as e: + print ("monitor IOError", e) + if e.errno == _errno.EINTR: + # raised when the computer wakes from sleep + # in this case, just restart the monitor + continue + raise + def enumerate(vendor_id=None, product_id=None, interface_number=None, driver=None): """Enumerate the HID Devices. diff --git a/lib/logitech/unifying_receiver/receiver.py b/lib/logitech/unifying_receiver/receiver.py index 1d0a3a1f..bbd4d910 100644 --- a/lib/logitech/unifying_receiver/receiver.py +++ b/lib/logitech/unifying_receiver/receiver.py @@ -388,3 +388,5 @@ class Receiver(object): _log.exception("open %s", path) if e.errno == _errno.EACCES: raise + except: + _log.exception("open %s", path) diff --git a/lib/solaar/listener.py b/lib/solaar/listener.py index 740c052b..50319be6 100644 --- a/lib/solaar/listener.py +++ b/lib/solaar/listener.py @@ -66,12 +66,12 @@ class ReceiverListener(_listener.EventsListener): if _log.isEnabledFor(_DEBUG): _log.debug("%s: polling status: %s", self.receiver, list(iter(self.receiver))) - if self._last_tick > 0 and timestamp - self._last_tick > _POLL_TICK * 3: - # if we missed a couple of polls, most likely the computer went into - # sleep, and we have to reinitialize the receiver again - _log.warn("%s: possible sleep detected, closing this listener", self.receiver) - self.stop() - return + # if self._last_tick > 0 and timestamp - self._last_tick > _POLL_TICK * 2: + # # if we missed a couple of polls, most likely the computer went into + # # sleep, and we have to reinitialize the receiver again + # _log.warn("%s: possible sleep detected, closing this listener", self.receiver) + # self.stop() + # return self._last_tick = timestamp