f



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

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 n=
ot able to understand why. The issue is easily reproducible on win 2008 ser=
ver and other multi core machines. Am I doing something wrongly? What is th=
e best way to do this?

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

Following are the files I am using=20

********
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] =3D=3D 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} !=3D "" } {
	puts 1
	fileevent $imChannel1 readable [set out1 [isProcessDone $imChannel1 $out1]=
]
	puts 11
	puts $out1
}

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

puts "bye"

exit 0

****=20
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.=20

TIA.
Deepanshu
0
6/20/2012 9:57:05 AM
comp.lang.tcl 23428 articles. 2 followers. Post Follow

4 Replies
1064 Views

Similar Articles

[PageSpeed] 23

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
0
wortkarg2 (425)
6/20/2012 2:48:14 PM
On Wednesday, June 20, 2012 8:18:14 PM UTC+5:30, Harald Oehlmann wrote:
> 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


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.
0
6/20/2012 3:55:19 PM
On Jun 20, 5:55=A0pm, Deepanshu <pahujadeepan...@gmail.com> wrote:
> On Wednesday, June 20, 2012 8:18:14 PM UTC+5:30, Harald Oehlmann wrote:
> > 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
>
> 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 mentio=
ned and =A0run it on a console.
> Have not tried on Unix yet.

Thanks.
I would try on Tcl 8.5.11...
0
wortkarg2 (425)
6/20/2012 4:51:24 PM
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
nospam6520 (256)
6/30/2012 11:31:47 AM
Reply: