Re: Problem with GLib.spawn_async / GLib.child_watch_add
- From: "Jasper St. Pierre" <jstpierre mecheye net>
- To: Neil Bird <gnome fnxweb com>
- Cc: gnome-shell-list gnome org
- Subject: Re: Problem with GLib.spawn_async / GLib.child_watch_add
- Date: Mon, 14 May 2012 14:05:24 -0400
On Mon, May 14, 2012 at 2:02 PM, Neil Bird <gnome fnxweb com> wrote:
>
> I need to be able to run a command from an extension, and as this may take
> a while I want to run it async and catch the process completing. However,
> there's something screwy with spawn_async that's stopping the
> child_watch_add from working. gnome-shell itself has code akin to this, so
> I don't know what I'm doing wrong.
>
> In the following test case, a “sleep” is spawned, but if you do a “pstree
> -pal” while it's active, the child process is actually not created as a
> child. So, when the child_watch_add tries to do a waitpid() call (ref.
> strace -eprocess -f) it fails with ECHILD (pid is not a child) and my
> callback never occurs.
>
> Is it broken or am I doing something stupid?
>
>
> #!/usr/bin/gjs
>
> const GLib = imports.gi.GLib;
> const Gtk = imports.gi.Gtk;
>
> // Initialize GTK+
> Gtk.init(null, 0);
>
>
> // Supposed to handle end of process
> function jobby()
> {
> print("In jobby");
> }
>
>
> let [success, pid] = GLib.spawn_async(
> null,
> ['sleep', '5'],
> null,
> GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.NO_NOT_REAP_CHILD,
DO_NOT_REAP_CHILD
> null );
> if (success && pid != 0)
> {
> // Wait for answer
> print("created process, pid=" + pid);
> GLib.child_watch_add( GLib.PRIORITY_DEFAULT, pid, function(pid,status) {
> GLib.spawn_close_pid(pid);
> print("process completed, status=" + status);
> jobby();
> });
> }
> else
> {
> print("failed process creation");
> }
>
> // Main loop
> Gtk.main();
>
>
> --
> [phoenix@fnx ~]# rm -f .signature
> [phoenix@fnx ~]# ls -l .signature
> ls: .signature: No such file or directory
> [phoenix@fnx ~]# exit
>
> _______________________________________________
> gnome-shell-list mailing list
> gnome-shell-list gnome org
> http://mail.gnome.org/mailman/listinfo/gnome-shell-list
--
Jasper
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]