本文介绍了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 answerPlease helpThank you

推荐答案

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

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

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

1403页,肝出来的..

09-06 22:54