python - Am I using Gio GFile monitor_file wrong? -
i'm using gio monitor_file this.
def callback(*args): print 'ok' gio_pointer = gio.file.new_for_path(os.environ['home']+'/temp') monitor = gio_pointer.monitor_file(gio.filemonitorflags.none, none) monitor.connect("changed", callback)
nothing happens modified file. gio works other file operations creation, read, , write.
am using wrong, or system problem?
my environment: gtk graphics, python, linux ubuntu 12.10, regular pc.
it failing because gobject's main loop required in order signals work.
the following complete example works me:
import os gi.repository import gtk, gio # allows ctrl+c exit program import signal signal.signal(signal.sigint, signal.sig_dfl) def callback(m, f, o, event): # without check, multiple 'ok's printed each file change if event == gio.filemonitorevent.changes_done_hint: print ('ok') gio_file = gio.file.new_for_path(os.environ['home']+'/temp') monitor = gio_file.monitor_file(gio.filemonitorflags.none, none) monitor.connect("changed", callback) gtk.main()
Comments
Post a Comment