33
33
import softwarecenter.paths
34
34
from softwarecenter.paths import PistonHelpers
36
from gi.repository import GObject
36
from gi.repository import GObject, GLib
38
38
LOG = logging.getLogger(__name__)
52
52
"error": (GObject.SIGNAL_RUN_LAST,
58
58
def __init__(self, format="pickle"):
59
59
super(SpawnHelper, self).__init__()
93
93
if "SOFTWARE_CENTER_DISABLE_SPAWN_HELPER" in os.environ:
96
(pid, stdin, stdout, stderr) = GObject.spawn_async(
96
(pid, stdin, stdout, stderr) = GLib.spawn_async(
97
97
cmd, flags=GObject.SPAWN_DO_NOT_REAP_CHILD,
98
98
standard_output=True, standard_error=True)
99
99
LOG.debug("running: '%s' as pid: '%s'" % (cmd, pid))
100
self._child_watch = GObject.child_watch_add(
101
pid, self._helper_finished, data=(stdout, stderr))
102
self._io_watch = GObject.io_add_watch(
103
stdout, GObject.IO_IN, self._helper_io_ready, (stdout, ))
100
self._child_watch = GLib.child_watch_add(
101
GLib.PRIORITY_DEFAULT, pid, self._helper_finished,
102
data=(stdout, stderr))
103
channel = GLib.IOChannel.unix_new(stdout)
104
self._io_watch = GLib.io_add_watch(
105
channel, GLib.PRIORITY_DEFAULT, GObject.IO_IN,
106
self._helper_io_ready, (stdout, ))
105
108
def _helper_finished(self, pid, status, (stdout, stderr)):
106
109
LOG.debug("helper_finished: '%s' '%s'" % (pid, status))
120
123
if self._io_watch:
121
124
# remove with a delay timeout delay to ensure that any
122
125
# pending data is still flushed
123
GObject.timeout_add(100, GObject.source_remove, self._io_watch)
126
GLib.timeout_add(100, GLib.source_remove, self._io_watch)
124
127
if self._child_watch:
125
GObject.source_remove(self._child_watch)
128
GLib.source_remove(self._child_watch)
127
130
def _helper_io_ready(self, source, condition, (stdout,)):
128
131
# read the raw data