1 from gi.repository import GObject
3 def spawn_child(command, callback):
4 """Spawn a child process with GObject and attach a callback to the
5 termination of the spawned process.
8 @param command: an argument vector. First element is used as argv[0] and
9 used as executable to look up in $PATH.
10 @type callback: (pid, condition) -> None
11 @param callback: is executed when the command completes
13 @returns: the child process pid
15 ret = GObject.spawn_async(command,
16 flags=GObject.SPAWN_SEARCH_PATH | GObject.SPAWN_DO_NOT_REAP_CHILD)
19 GObject.child_watch_add(pid, callback)
22 class ScheduledFunction(object):
23 def __init__(self, interval, function):
26 @param interval: seconds
28 self.event = GObject.timeout_add(int(1000 * interval), function)
31 ret = GObject.source_remove(self.event)