471,312 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,312 software developers and data experts.

possible to preserve subprocess.Popen objects for later?

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

Jun 21 '07 #1
3 1577
Ratko schrieb:
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...
This doesn't work. What could work is that you create a python spawning
process that lives as long as all it's popened childrend - and then let
the gui connect to that, by whatever IPC means you like. E.g. pyro.

Diez
Jun 21 '07 #2
On Jun 21, 6:32 pm, Ratko <rjago...@gmail.comwrote:
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

Jun 22 '07 #3
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.
Unfortunately I don't have control over the processes that I am
running (they are components of a much larger system that I am trying
to bring under one roof).

However, it seems that a named pipe might work. Is it possible to set
up a named pipe for a process that I start and tell that process to
direct all its output to it?

Thanks,
Ratko

Jun 22 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Nicolas Fleury | last post: by
5 posts views Thread by Dara Durum | last post: by
5 posts views Thread by Grant Edwards | last post: by
12 posts views Thread by Eric_Dexter | last post: by
9 posts views Thread by Phoe6 | last post: by
reply views Thread by Joe Blow | last post: by
12 posts views Thread by bhunter | last post: by
25 posts views Thread by Jeremy Banks | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.