Exec() - The right way to go?

Hello,

Thats another excellent example thanks, however, the problem remains that I
am able to get a full report back from the child thread, but only when it

has been closed!

Iv tried to collect information using a timer, but that has not worked yet.
I’m missing something in my understanding here, I’m sure of it. The examples
Iv seen all do exactly what they claim, but their return values are always

returned in one go when the child thread closes and the main thread remains
usable while the child is running.

However I need the output from the child thread to be continually reported
to the main thread and so far Iv not seen any examples of this (except

perhaps your module, which I have difficulty following anyway)

Can you perhaps give me a pointer to what I’m missing?

How are you reading from the processes out pipe? Just a read()?

Because this will block and not return anything until all output has been read or the pipe has been closed.You should also do a nonblocking read by only reading a little bit at a time.

i.e)

while not abort:

txt = proc.stdout.read(4096)

if txt:

wx.PostEvent(myhandler, MyEvent(type, id, value=txt)

OR wx.CallAfter(myTextCtrl.AppendText, txt)

else:

break

Note: instead of an arbitrary 4096 it would be better to check how much is available before reading each time. I leave this as an exercise to the reader.

Cody

···

On Fri, Mar 27, 2009 at 9:15 AM, MaxVK maximvonk@gmail.com wrote:

Hello,

···

On Fri, Mar 27, 2009 at 1:28 PM, MaxVK maximvonk@gmail.com wrote:

Everything still works, my main thread is still accessible, but any output
from the child thread is still only returned when that thread is closed (at
the moment thats only when I manually close the frame of the child thread.

Any ideas where I’m (still) going wrong?

  1. Have you checked if your PostEvent calls are being made and if the event handler for the events your posting is being called? If it is it could just be a refresh issue.

  2. Its also possible that your process is putting out less than 4096 of data and that is why I said you should check how much and if there is anything to read before blocking on the read call. For Linux/Unix see ‘select’ and ‘fcntl’, for windows see ‘ctypes’ and PeekNamedPipe.

Anyhow all the answers have already been put in front of you so you just need to work on it.

cody

Okay - Select.

Iv got this:
        self.proc = subprocess.Popen([self.Arg1, self.Arg2],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

        while not self._want_abort:
            if select.select([self.proc.stdout],[], []):#,10):
                print "PAST SELECT"

but the print statement is only run when the child thread quits. Looking at
the documents it seemed that IF there were something in stdout, the code
should run past the select.select() but it doesn't.

Something else Iv missed? Iv been bashing at this all day now and I'm no
closer than I was this morning - I'm off to bed.

cheers

Max

···


View this message in context: http://www.nabble.com/Exec()---The-right-way-to-go--tp22721540p22751932.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Right. After another 4 hours of thrashing about and getting no further than I
did yesterday morning I tried to use the wxProcess example from the demo -
Lo and behold, it works. So I dropped the panel from the demo, directly onto
a frame and tried it - It doesn't work - Same problem as always, in that the
data from the child thread (process) only gets through when the thread
closes.

Since this was the code that worked in the demo, dropped directly into a
frame, I thought that perhaps it was something to do with the editor I was
using, so I ran the code from the console. Still doesn't work. The child
thread (process) still works fine, but all output is blocked until it
closes.

What on earth am I doing wrong? Its nearly twenty hours now, and this last
time I copied some *working* code directly from the demo with no editing at
all, and it still fails as soon as I try it.

Cheers

Max

···


View this message in context: http://www.nabble.com/Exec()---The-right-way-to-go--tp22721540p22756327.html
Sent from the wxPython-users mailing list archive at Nabble.com.