简体   繁体   中英

udev interface for python3?

Is there any example on how to capture udev events in Python3? I can't get events working at all in.237 (or 1.0?). And couldn't get any examples of GUdev with Introspection.

I'm not sure where the problem lies. I found an example test.py but there, parameters are given when instantiating Client like in client = GUdev.Client(['block']) . Those parameters are not accepted in the actual version ( TypeError: GObject.__init__() takes exactly 0 arguments (1 given) ).

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('GUdev', '1.0')
from gi.repository import Gtk, GUdev, GLib

def on_uevent(client, action, device):
    print(action)

client = GUdev.Client()
client.connect('uevent', on_uevent)

GLib.MainLoop().run()

Ah, well. Seems the G(NU|nome|object)-Introspection changed a few things in its workings.

...
client = GUdev.Client.new(['block'])
client.connect('uevent', on_uevent)
...

works fine. I don't know why the old syntax (see above) doesn't throw any errors...

BTW, GUdev.Client.new(['block']) accepts multiple values in the list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM