Tcl/Tk hang on windows

Posted by drmick on 2011-01-18 23:54

Hi everybody,

Please forgive me if my problem is a common one, but .. I'm not able to find any solution nor any related discussion on a similar one.

Here is the problem. I'm working on a multi-platform software, and just develop something that works on linux but leads to a bug on windows.

Basically, I have a tcl executable A.tcl (tclapp starpack 8.5.9), which run another tcl executable B.tcl (tclapp starpack 8.5.9) which will run a binary executable (let's say Binary.exe).

The problem is on WinXP and Win7. Eveything seems to run fine, except that when B.tcl runs Binary.exe, it hangs during an random time (from 2mn to 15 !!) and then runs as expected.

This seems to be a race condition, due to the fact that B.tcl is opened in r+ mode AND that a script is connected to stdin.

I just found a way to resume the problem with two simple scripts, so here they are:

 
=====================================================================
A.tcl
=====================================================================
#!/bin/bash
# the next line restarts using wish \
exec wish8.5 "$0" -- "$@"

set Commande [ file join [pwd] B.tcl ]
set Canal [open |[list wish85.exe $Commande ] r+ ]

and

 
=====================================================================
B.tcl
=====================================================================
#!/bin/bash
# the next line restarts using wish \
exec wish8.5 "$0" -- "$@"

   proc InteractiveExecute {} {
        #Par defaut tout va bien
        set ReturnValue true
            #Lire la commande sur stdin
            if { [ gets stdin Commande] > -1 } {
                #Do some stuff            }

        if { [ eof stdin ] == 1 } {
            fileevent stdin readable ""
        }
        return $ReturnValue
    }

    fileevent stdin readable InteractiveExecute
    fconfigure stdin -blocking false -buffering line

update
exec Binary.exe
=====================================================================

It seems an interaction between the "update" command and the event on stdin readable. If update command disapears, everythings works. If script "InteractiveExecute" is not linked, everythings works !

Michael
--
Michael Magoga. e-mail : drmick@magoga.net