473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 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 1693
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nicolas Fleury | last post by:
Hi, I want to use the subprocess module (or any standard Python module) to run a process: - which stdout and stderr can each be redirected to any file-like object (no fileno function). - can be...
5
by: Dara Durum | last post by:
Hi ! I want to create a Process Pool Object. I can hold started processes, and can communicate with them. I tryed with many ipc methods, but every of them have bug or other problem. Sockets...
5
by: Grant Edwards | last post by:
I'm trying to use the py-gnuplot module on windows, and have been unable to get it to work reliably under Win2K and WinXP. By default, it uses popen(gnuplotcmd,'w'), but in some situations that...
12
by: Eric_Dexter | last post by:
I am trying to modify a programming example and I am coming up with two problems... first is that I can't seem to pass along the arguments to the external command (I have been able to do that with...
9
by: Phoe6 | last post by:
Hi all, Consider this scenario, where in I need to use subprocess to execute a command like 'ping 127.0.0.1' which will have a continuous non- terminating output in Linux. # code # This...
0
by: Joe Blow | last post by:
I'd like to use the subprocess module to create a pipeline with a fork. For example, what if I wanted a "cat" process to send a file to both an "md5sum" process and a "gzip" process. In bash, I'd...
12
by: bhunter | last post by:
Hi, I've used subprocess with 2.4 several times to execute a process, wait for it to finish, and then look at its output. Now I want to spawn the process separately, later check to see if it's...
4
by: Tobiah | last post by:
I am not sure how to capture the output of a command using subprocess without creating a temp file. I was trying this: import StringIO import subprocess file = StringIO.StringIO() ...
25
by: Jeremy Banks | last post by:
Hi. I wondered if anyone knew the rationale behind the naming of the Popen class in the subprocess module. Popen sounds like the a suitable name for a function that created a subprocess, but the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.