Here is a Glibmm example, you should be able to translate it easily to Python:
int child_pid;
int child_stdout;
Glib::spawn_async_with_pipes("", std::vector<std::string>{"ping", "192.168.1.1"}, Glib::SPAWN_SEARCH_PATH|Glib::SPAWN_STDERR_TO_DEV_NULL, sigc::slot<void>(), &child_pid, nullptr, &child_stdout);
Glib::RefPtr<Glib::IOChannel> ch_out = Glib::IOChannel::create_from_fd(child_stdout);
Glib::RefPtr<Glib::IOSource> src_out = ch_out->create_watch(Glib::IO_IN);
src_out->connect([ch_out](Glib::IOCondition cond){ return handle_stdout(cond, ch_out); });
src_out->attach(Glib::MainContext::get_default());
bool handle_stdout(Glib::IOCondition cond, Glib::RefPtr<Glib::IOChannel> ch) {
Glib::ustring text;
ch->read_line(text);
textview->get_buffer()->insert(textview->get_buffer()->end(), text);
return true;
}
Edit: One should also call src_out->destroy()
when done reading to remove it from the event loop.