Re: monitoring the progress of a child process
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: monitoring the progress of a child process

From: Donal K. Fellows <donal.k.fellows@manchester.ac.uk>
Date: Wed May 25 2005 - 13:03:42 CEST

William J Poser wrote:
> Here is MinpairPipeEvent:
>
> proc MinpairPipeEvent {PipeHandle Start} {
> global ElapsedTime
> global StdoutResult
> if {[eof $PipeHandle]} {
> set ElapsedTime [expr {[clock seconds] - $Start}]
> ShowMessage [format [_ "Elapsed time: %d seconds"] $ElapsedTime];
> catch {[close $PipeHandle]};
> } else {
> set StdoutResult [read $PipeHandle]
> }
> }

That's wrong. Even you set the pipe channel to be non-blocking, that'd
*still* be wrong (but not quite *as* wrong; you'd just be throwing data
away instead of keeping around properly, which might even be OK with
suitable traces; that's your call). But since you never turn off
blocking, that's just plain wrong. (You also have some bizarre syntax in
your [catch] commands but that's by-the-by.)

> I don't see anything in here that would cause the problem,
> but maybe I'm missing something.

Yes. You're missing:
   fconfigure $PipeHandle -blocking 0
That's making the [read $PipeHandle] block until the pipe is closed by
the other end. That's the source of your troubles. Once you've got rid
of the blocking, you'll have to think about accumulators, and you might
even end up with this:

   proc MinpairPipeEvent {handle start} {
      global ElapsedTime StdoutResult
      fconfigure $handle -blocking 0
      set data [read $handle]
      if {[eof $handle]} {
         set ElapsedTime [expr {[clock seconds] - $start}]
         ShowMessage "Elapsed time: $ElapsedTime seconds"
         if {[catch {close $handle} msg]} {
            # Deal with error exit?
         }
      } elseif {![fblocked $handle]} {
         append StdoutResult $data
      }
   }

Donal.
Received on Thu Sep 29 14:18:55 2005