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

查看:27
本文介绍了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天全站免登陆