(Python) glib MonitorObserver return two exception when attach (or detach) usb device. Why?

28 views Asked by At

I use this code to monitor usb device:

context = Context()
monitor = Monitor.from_netlink(context)
monitor.filter_by(subsystem='usb')
monitor.poll(1.5)
observer = MonitorObserver(monitor)
observer.connect('device-event', device_event)
monitor.start()
glib.MainLoop().run()

'device_event' function receive the exception with associated action:

add if usb device is added

remove if usb device is removed

so, when device is added my function do somethings and when is removed my function do somethings.

The problem is that my function receive two exception when the device is added and two exception when the device is removed:

Device(u'/sys/devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb2/2-2/2-2.2') Device(u'/sys/devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb2/2-2/2-2.2/2-2.2:1.0')

I would only one exception.

0

There are 0 answers