TCL pipe filehandle to avoid disk-access slowdown -


i running eda product. product gives api, input like. however, output submitted file-handle. i.e.:

getfoodata -elem <elem query> -query <what queried> -fh <file handle> 

this means if want more crunching, need read input in file handle, after writing process finished, or risk o(2) algorithm. data can enormous, , our filer system slow/overloaded/out-quota (or combination). there way me "catch" data should output file handle, creating file-handle not output file system? ideally i'd this:

getfoodata -elem <elem query> -query <what queried> -fh $fh set m [ getlatestinputofpipefh $fh ] 

thanks.

one option (tcl 8.5 , later) create "reflected channel", in-memory channel. wiki page listed below has complete examples.

assuming eda product still stuck on 8.4 (which quite old), need use standard file or pipe.

you don't mention operating system on. on unix can create named pipe. while use filesystem, file should stay small enough stays in memory time.

proc processfooinput { fh } {    set data [gets $fh]    # process data    if {[eof $fh]} {       fileevent $fh readable {}    } }  set pfn /tmp/foodata exec mkfifo -m 0666 $pfn set outfh [open $pfn w] set infh [open $pfn r] fconfigure $infh -blocking 0 -buffering line fileevent $infh readable processfooinput getfoodata -elem <elem query> -query <what queried> -fh $outfh 

apparently windows has named pipes accessed via internal api, they're bit harder use (and i've never used them).

if don't have named pipe, need use file:

set sfn /var/tmp/foodata.tmp set outfh [open $sfn w] set infh [open $sfn r] fconfigure $infh -blocking 0 -buffering line fileevent $infh readable processfooinput getfoodata -elem <elem query> -query <what queried> -fh $outfh 

references: refchan; wiki: reflected channel; chan; fileevent; fconfigure


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -