Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"backgrounding" a procedure?

14 views
Skip to first unread message

Greg.A....@gmail.com

unread,
Oct 16, 2007, 5:29:38 PM10/16/07
to
I have a TCL code which takes some user input and executes some
Fortran (via 'exec'). The Fortran goes off and crunches some numbers
for 5 minutes or so, and then TCL does some parsing of the results.
The way things are currently set up, I have to wait for the Fortran to
return with the results so that TCL can finish parsing. Then I can
arrange some more input on the "front side", and send it off again.

Ultimately, what I'm trying to set up is queuing system (although
nothing quite so...rigorous). I'd like to be able to arrange some
input for the FORTRAN, send it on its merry way, along with some
instructions regarding what to do when it finishes, and then arrange
some more input (without the 5 minute wait).

Is there a way to spawn off separate instances of a procedure within
TCL? I realize that this could be potentially dangerous territory if
the spawning procedure has any reach back to its originating
namespace. Hopefully I've explained things well enough.

Can anyone think of a different (better?) way of tackling this?

Thanks, this group really is a tremendous resource for us amateurs.

Greg

Jan Kandziora

unread,
Oct 16, 2007, 5:45:46 PM10/16/07
to
Greg.A....@gmail.com schrieb:

>
> Is there a way to spawn off separate instances of a procedure within
> TCL? I realize that this could be potentially dangerous territory if
> the spawning procedure has any reach back to its originating
> namespace. Hopefully I've explained things well enough.
>
There are two possibilities:

1. Setup event driven read/write from a pipe. This may be done by
using "exec" with redirections or by using open "|fortranprogram" "r+" ,
both times involving the "fileevent" command. This is the method I prefer,
as there is *no* concurrency. There is only one execution path at a time,
new events are only processed when then current code snippet finished its
work and returned to the event loop.


2. Enabling Tcl threading and open a second interpreter (==thread) for the
exec call. This solution seems simple but gives you all the hurtings of
permanent concurrency, as it affects *all* interpreters.


Kind regards

Jan

Michael Schlenker

unread,
Oct 16, 2007, 6:08:39 PM10/16/07
to
Greg.A....@gmail.com schrieb:

> I have a TCL code which takes some user input and executes some
> Fortran (via 'exec'). The Fortran goes off and crunches some numbers
> for 5 minutes or so, and then TCL does some parsing of the results.
> The way things are currently set up, I have to wait for the Fortran to
> return with the results so that TCL can finish parsing. Then I can
> arrange some more input on the "front side", and send it off again.
>
> Ultimately, what I'm trying to set up is queuing system (although
> nothing quite so...rigorous). I'd like to be able to arrange some
> input for the FORTRAN, send it on its merry way, along with some
> instructions regarding what to do when it finishes, and then arrange
> some more input (without the 5 minute wait).
>
> Is there a way to spawn off separate instances of a procedure within
> TCL? I realize that this could be potentially dangerous territory if
> the spawning procedure has any reach back to its originating
> namespace. Hopefully I've explained things well enough.

Look at the fileevent example by Kevin Kenny on this page:
http://wiki.tcl.tk/880

Maybe also useful:
http://wiki.tcl.tk/3359
http://wiki.tcl.tk/4004
http://wiki.tcl.tk/8507

Michael

Uwe Klein

unread,
Oct 17, 2007, 4:02:54 AM10/17/07
to
Aside from the advice already given you may want to have a look at
bgexec ( standalone or from blt )
http://wiki.tcl.tk/_search?S=bgexec

uwe

Glenn Jackman

unread,
Oct 17, 2007, 9:58:37 AM10/17/07
to
At 2007-10-16 05:29PM, "Greg.A....@gmail.com" wrote:
> I have a TCL code which takes some user input and executes some
> Fortran (via 'exec'). The Fortran goes off and crunches some numbers
> for 5 minutes or so, and then TCL does some parsing of the results.
> The way things are currently set up, I have to wait for the Fortran to
> return with the results so that TCL can finish parsing. Then I can
> arrange some more input on the "front side", and send it off again.
>
> Ultimately, what I'm trying to set up is queuing system (although
> nothing quite so...rigorous). I'd like to be able to arrange some
> input for the FORTRAN, send it on its merry way, along with some
> instructions regarding what to do when it finishes, and then arrange
> some more input (without the 5 minute wait).
>
> Is there a way to spawn off separate instances of a procedure within
> TCL? I realize that this could be potentially dangerous territory if
> the spawning procedure has any reach back to its originating
> namespace. Hopefully I've explained things well enough.

Read up on the after command:
http://www.tcl.tk/man/tcl8.4/TclCmd/after.htm

proc long_command {} {
puts starting...
after 5000
puts ...done
}
puts "invoking long_command in the background"
after 0 long_command
puts "long_command launched."

--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry

0 new messages