possible to preserve subprocess.Popen objects for later?

zacherates zacherates at gmail.com
Thu Jun 21 22:14:03 EDT 2007


On Jun 21, 6:32 pm, Ratko <rjago... at gmail.com> wrote:
> Hi all,
>
> I have a python gui app that launches multiple applications using
> subprocess.Popen class and prints their output in the gui (using
> PIPEs, threads and wxPython). Everything works great but the problem
> is that some applications should run in the background (ie they don't
> close when the gui closes) so next time when you start the gui it will
> not have a handle on those processes that are still running and
> therefore won't be able to print their output.
>
> So, I was wondering if there is any way to "preserve" the Popen object
> of those background processes and reload them when the gui is
> restarted? Ideally I would like to have the whole Popen object
> preserved but I could also get by with just the Popen.stdout file
> object. I can save the Popen.stdout.fileno() integer because that's
> what I use in os.read() to read the output anyway but that doesn't
> work.
>
> I have doubts that this could even conceptually work but I thought I'd
> try asking anyway. I don't have a full understanding of how processes
> and pipes work on the system level...
>
> Thanks,
> Ratko

Sounds like you might want to consider running the backround task as
either a service or daemon  and communicate via a TCP/IP connection or
a named pipe rather than using STDIN/OUT.  Actually you could use
either idea without actually setting up a daemon.

Also, you're generally supposed to wait() for your children to die
(even if you stop the gui) rather than let them become zombies.

Cheers,
   Aaron




More information about the Python-list mailing list