Multiple fileevents for multiple process pipelines? 
Author Message
 Multiple fileevents for multiple process pipelines?

Being a newbie, I am just now getting a handle on the fileevent usage.
However, I am only opening up two simultaneous process pipelines and then using
two fileevents to handle the communication to those two processes.  See code
sniplet (this is using expectk GUI, whereas the script that is opened is an
expect script):

set f [open "|newer.exp $ip_address $proc1 $proc2 $size $delay" r+]
fconfigure $f -buffering line -blocking 0
fileevent $f readable [list handleInput $f]

set g [open "|newer.exp $ip_address $proc1 $proc2 $size $delay" r+]
fconfigure $g -buffering line -blocking 0
fileevent $g readable [list handleInput $g]

However, awhile back someone mentioned they wanted to open several hundred
scripts running in the background.  If one wanted to be able to communicate to
all those process pipelines, does that mean you have to create hundreds of
lines just like the six lines above?  In the future I may need to talk to as
many as 12 processes running at once, it seems like there is a better way to do
this without having to type all the same lines with another fileevent and
fileid variable each time...  Would someone enlighten me on this one please?



Fri, 27 Aug 2004 04:15:34 GMT  
 Multiple fileevents for multiple process pipelines?

Quote:

> fileid variable each time...  Would someone enlighten me on this one please?

foreach thing {one two three four five} {
  set f [open "|$thing ...."]
  fconfigure $f ...
  filevent $f readable [list handleInput $f]

Quote:
}

There's no reason not to reuse "$f" in several places. Just remember
that you have to close it in handleInput when you get EOF.

--
Darren New
San Diego, CA, USA (PST). Cryptokeys on demand.
  To the user, everything works just as expected,
    assuming the user's expectations are correct.



Fri, 27 Aug 2004 04:43:21 GMT  
 Multiple fileevents for multiple process pipelines?

Quote:


> > fileid variable each time...  Would someone enlighten me on this one please?

> foreach thing {one two three four five} {
>   set f [open "|$thing ...."]
>   fconfigure $f ...
>   filevent $f readable [list handleInput $f]
> }

> There's no reason not to reuse "$f" in several places. Just remember
> that you have to close it in handleInput when you get EOF.

This doesn't seem to work.  Using this example would not allow you to
communicate to the multiple pipelines since $f is set to the last id
and remains set.  There is now no way to communicate to the previous
pipelines open.

It appears the code should be more like...

foreach thing {f g h i j} {
   set thing [open "|ping.exp ..." r+]
   fconfigure $thing ...
   fileevent $thing readable [list handleInput $thing]

Quote:
}

Any gurus out there to (dis)prove the above example?


Fri, 27 Aug 2004 10:57:13 GMT  
 Multiple fileevents for multiple process pipelines?

Quote:

> This doesn't seem to work.  Using this example would not allow you to
> communicate to the multiple pipelines since $f is set to the last id
> and remains set.  There is now no way to communicate to the previous
> pipelines open.

Sure. You communicate to said pipelines within handleInput. If you're
only reading, then that's fine. If you're also writing, you probably
want a writable event.

Otherwise, use an array to remember all the possible values for the file
handle, just like in any other language where you need multiple values
treated similarly.

If, however, handleInput says something like

proc handleInput {pipe} {
  if {[eof $pipe]} {close $pipe ; return}
  if {0 == [gets $pipe line]} {return}
  puts stdout $line

Quote:
}

then you have no problem. (Above code not checked or anything. Use at
your own risk.)

The thing to realize is that each successive value of $f will be stored
in the table of fileevent handlers. It's managed internally by
fileevent, so it isn't lost.

--
Darren New
San Diego, CA, USA (PST). Cryptokeys on demand.
  To the user, everything works just as expected,
    assuming the user's expectations are correct.



Fri, 27 Aug 2004 11:04:24 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Q: Multiple processes writing to a single process using Expect

2. Multiple edits, multiple files

3. Multiple CPUs and multiple PCs

4. Multiple DAQ boards/multiple VIs?

5. Multiple Dispatch (was Re: Replacing Multiple Inheritance with Java's Interfaces)

6. Multiple Windows on Multiple Machines

7. Multiple textures on one IndexFaceSet [multiple files, not a map]

8. Updating multiple fields on multiple rows

9. TCLLib cmdline - multiple file names and multiple invocations

10. Multiple INCLUDE Vs multiple USE

11. Multiple lsearch and multiple list delete

12. multiple listboxes with multiple select

 

 
Powered by phpBB® Forum Software