[pygtk] Fwd: pygobject: Updating mount information outside of the glib event loop?

Johan Dahlin johan at gnome.org
Fri Nov 14 19:14:46 WST 2008


---------- Forwarded message ----------
From: Stefan Farestam <stefan at farestam.net>
Date: Thu, Nov 13, 2008 at 9:21 PM
Subject: pygobject: Updating mount information outside of the glib event loop?
To: johan at gnome.org



Hi Johan,

I'm attempting to hack up a small fuse-based automounter in python for
gvfs and ran across the python gio library. Very nice! However, the
fuse library has its own event loop and it seems like information
about mounts in gio is not updated unless the glib event loop is
executed. Can I mix the two event loops somehow, or is there any other
way to get around this and force the mount information to become
updated?

As an example, here is a code snippet that I use to list active mounts:

-----------------------------------------------
#!/usr/bin/python

import gio, time

while [ 1 ]:
 volume_monitor=gio.volume_monitor_get()
 mounts = volume_monitor.get_mounts()
 for mount in mounts:
     print mount.get_name()
 time.sleep(1)
-----------------------------------------------

Now, if I launch the above code and manually mount and unmount a share
using another terminal window by doing

 gvfs-mount       smb://10.1.1.102/media-ro
 gvfs-mount    -u smb://10.1.1.102/media-ro

then I see no change in the shares listed.

However, if I "bastardize" the above with the following, then it works fine:

-----------------------------------------------
#!/usr/bin/python

import gio, time, glib

class Idle(glib.Idle):
  def __init__(self, loop):
      glib.Idle.__init__(self)
      self.set_callback(self.callback, loop)

  def callback(self, loop):
      loop.quit()

loop = glib.MainLoop()

while [ 1 ]:
 volume_monitor=gio.volume_monitor_get()
 mounts = volume_monitor.get_mounts()
 print "--- mounts"
 for mount in mounts:
     print mount.get_name()
 idle = Idle(loop)
 idle.attach()
 loop.run()
 time.sleep(1)
-----------------------------------------------


Many thanks for any insight on this,
Stefan

--
Stefan Farestam
Mobile: +46 70 649 6838


More information about the pygtk mailing list