Pyudev-调用两次函数 [英] Pyudev - calls function twice

查看:61
本文介绍了Pyudev-调用两次函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对pyudev库的使用有疑问.

I have a problem with pyudev library usage.

我想要一个程序,该程序可以检测USB插入并向控制台打印一些内容.这是我的代码:

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()

问题是当我运行脚本时,似乎device_event函数被调用了两次.当我插入USB设备时得到的输出是:

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

推荐答案

您将获得设备枚举的事件,然后为每个枚举的接口分离事件.

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

这篇关于Pyudev-调用两次函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆