It will *probably* only be used on
Windows systems
Now you tell me! I was thinking about this and wrote up a little sample
in Linux. It won't work on Windows, but you might be able to figure out
how to translate it to Windows stuff. What I did was use a File In File
Out (FIFO) to communicate between he two process. The Master program
creates the FIFO, starts the salve, passing in the name of the FIFO and
then reads from it, and destroys it when it is done. The Slave program
writes to the FIFO and it's log file, until it is closed and then the
write fails, and the exception is caught, and it stops trying to write
to the FIFO. I'm sure all this could be done with pipes, but I couldn't
figure out how to create a pipe between a parent and child process.
Unfortunately for you, I don't think Window supports FIFOs.
The other trick was that you need the slave process to be forked, so
that it won't die when the Master process is shut down. I found some
code in the Python Cookbook at Activestate to help with that. Again,
this is *nix code. Frankly, you'd think there would be a call to "start
a new program as a new process, not as a child", but I couldn't readily
figure it out.
Enclosed are master.py and slave.py. Put them in the same directory and
fire up slave.py (on *nix) and it should all work. The file:
junkoutput.txt will be created by the slave program.
Of course the primary alternative I have been considering is the "monitor
the file and update the window" approach, but I was concerned about just
how to do this (say by using EVT_IDLE, EVT_UPDATE_UI?) in a reasonably
efficient manner. I really wanted to be sure there wasn't some
particularly slick way of doing this within wxPython that I had somehow
missed.
Depending on how often you want the window updated, I probably wouldn't
use a straight EVT_IDLE. You should use a wxTimer, set for say a couple
seconds, and it would fire off a routine that read anything additional
in the file, and then start a new timer. You could also do the file
checking and reading in a separate thread (again probably with a timer
of some sort), and then have it post an event when the UI needs
updating. See:
http://wiki.wxpython.org/index.cgi/LongRunningTasks
and
http://wiki.wxpython.org/index.cgi/WorkingWithThreads
(and Throbber.py in the demo) for some examples of using threads.
By the way, this is mostly a Python task, not a wxPython one. I'd post
the question to comp.lang.python, and I'll bet you will get some help
there.
-Chris
···
gary.h.merrill@gsk.com wrote:
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov