Pyudev - calls function twice

泪湿孤枕 提交于 2019-11-27 08:44:38

问题


I have a problem with pyudev library usage.

I want to have a program which detects USB plug in and prints something to console. Here's the code i have:

import glib
import os

import sys

from pyudev import Context, Monitor

from pyudev.glib import GUDevMonitorObserver as MonitorObserver
def device_event(observer, device):
  print 'yep'

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

The problem is when i run the script it seems that device_event function gets called twice. The output i get when i plug in an USB device is:

yep
yep

I searched all over but could not find an answer Please help Thank you


回答1:


You get an event for the device enumeration and then separate events for each enumerated interface.



来源:https://stackoverflow.com/questions/27964148/pyudev-calls-function-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!