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

tcl hangs on exit for multiple open calls from within same tcl script

67 views
Skip to first unread message

Deepanshu

unread,
Jun 20, 2012, 5:57:05 AM6/20/12
to
Hi,

I am looking to run a couple of processes in parallel. But a strange hang occurs randomly. I am invoking two tcl commands using open in parallel. Now after a while one of the process would just hang indefinitely which I am not able to understand why. The issue is easily reproducible on win 2008 server and other multi core machines. Am I doing something wrongly? What is the best way to do this?

To reproduce, you just have to create the files and run loop.bat. You should see the hang within 15-20 minutes.

Following are the files I am using

********
loop.bat
******
@echo off
:loop
tclsh 1.tcl
goto loop

*****************
Contents of file 1.tcl
*****************
#!/bin/sh
#DO NOT CHANGE THOSE 3 FIRST LINES \
exec tclsh $0 "$@"

set status [catch { exec tclsh 2.tcl } outcmd]
puts $outcmd
exit 0

*******
Contents of file 2.tcl
*****
#!/bin/sh
#DO NOT CHANGE THOSE 3 FIRST LINES \
exec tclsh $0 "$@"

set cmd1 "tclsh 6.tcl &"
set cmd2 "tclsh 5.tcl &"
set out1 ""
set out2 ""

proc isProcessDone { channel logText } {
gets $channel currentline
while {[eof $channel] == 0} {
set logText "$logText\n $currentline"
gets $channel currentline
}
return $logText
}

puts "hi"
set imChannel1 [open "| $cmd1"]
puts "hi1 $imChannel1"
set imChannel2 [open "| $cmd2"]
puts "hi2 $imChannel2"
#set imChannel3 [open "| $cmd"]


if { ${imChannel1} != "" } {
puts 1
fileevent $imChannel1 readable [set out1 [isProcessDone $imChannel1 $out1]]
puts 11
puts $out1
}

if { ${imChannel2} != "" } {
puts 2
fileevent $imChannel2 readable [set out2 [isProcessDone $imChannel2 $out2]]
puts 22
puts $out2
}

puts "bye"

exit 0

****
Contents of 5.tcl and 6.tcl
******
#!/bin/sh
#DO NOT CHANGE THOSE 3 FIRST LINES \
exec tclsh $0 "$@"

puts "\ncallexec 6 started"
puts "\ncallexec 6 terminated"

Please help.

TIA.
Deepanshu

Harald Oehlmann

unread,
Jun 20, 2012, 10:48:14 AM6/20/12
to
Sorry, no wizard here, but I am certain that your system and tcl
version is required to correctly answer the question. In addition,
locking issues may interfere, so information about the file system
(ex: nfs) may be helpful too.

-Harald

Deepanshu

unread,
Jun 20, 2012, 11:55:19 AM6/20/12
to
Sorry I missed the details.
OS - Win 2008 Server and Win 2007 (tried on both)
Tcl/Tk - 8.4.15
File System - NTFS

All tcl files are local to the system. You can create the files as mentioned and run it on a console.
Have not tried on Unix yet.

Harald Oehlmann

unread,
Jun 20, 2012, 12:51:24 PM6/20/12
to
Thanks.
I would try on Tcl 8.5.11...

Schelte Bron

unread,
Jun 30, 2012, 7:31:47 AM6/30/12
to
Deepanshu wrote:
> Hi,
>
> I am looking to run a couple of processes in parallel. But a
> strange hang occurs randomly. I am invoking two tcl commands
> using open in parallel. Now after a while one of the process
> would just hang indefinitely which I am not able to understand
> why. The issue is easily reproducible on win 2008 server and
> other multi core machines. Am I doing something wrongly? What is
> the best way to do this?
>
[snip]
>
> Please help.
>
> TIA.
> Deepanshu

I don't use windows myself and therefor I didn't run your code, but
I can see a number of issues with it. First of all you appear to be
confused about fileevents. The code you posted doesn't actually use
them, so you are not doing anything in parallel at all.

The fileevent commands takes a script that will be executed when
data becomes available on the channel. Your code just reads the
channel until it reaches eof and then passes that as the script
argument to the fileevent command. It then does the same thing for
the second command. So completely serial.

The reason the strange fileevent script doesn't result in an error
is that you never enter the event loop, so the fileevent doesn't get
a chance to fire.

To use fileevents effectively you should also make your channels
non-blocking.

I don't know if fixing these issues will avoid the hang, but at
least it should make your code do something closer to what you think
it is doing.


Schelte.


0 new messages