id summary reporter owner description type status priority milestone component version resolution keywords cc i_links o_links 335 Terminate Tcl threads landauf landauf "Right now Tcl threads (see [wiki:TclThreadManager]) can't be terminated if the corresponding Tcl interpreter is executing an endless ([http://www.tcl.tk/man/tcl8.4/TclCmd/while.htm while]) or long ([http://www.tcl.tk/man/tcl8.4/TclCmd/for.htm for]) loop or waiting for a condition ([http://www.tcl.tk/man/tcl8.4/TclCmd/vwait.htm vwait]) or simply sleeping ([http://www.tcl.tk/man/tcl8.4/TclCmd/after.htm after]) and maybe it's even possible to hang on an open stream ([http://www.tcl.tk/man/tcl8.4/TclCmd/exec.htm exec] and [http://www.tcl.tk/man/tcl8.4/TclCmd/open.htm#M20 open with a pipe]). Since Tcl doesn't know keywords, all those language features are functions which can be overwritten with [http://www.tcl.tk/man/tcl8.4/TclCmd/proc.htm proc]. For example you could redefine while and for with an additional condition which becomes false as soon as you want to terminate the interpreter. Unfortunately this isn't as easy as expected, because you need some deep knowledge of Tcl including it's scoping policy and how to circumvent it. But maybe there's another way to safely terminate an interpreter. Tcl offers [http://www.tcl.tk/man/tcl8.4/TclLib/contents.htm many functions] and one of them might be the right one. But remember, you can't just crash the thread, it will crash everything. Except maybe with an ugly hack using a signal handler, but that won't be platform independent. A third option might be to simply interrupt the thread without even trying to stop the interpreter. That won't give us our memory back, but it surely will free the CPU which might be good enough if everything else fails. Fourth an last option that comes to my mind: As far as I know, Tcl uses some sort of events. Maybe it's possible to set up an event handler in Tcl and later inject the event through the Tcl C API to call the event handler which terminates the interpreter. Maybe not. " defect new minor Version 0.2 Codename: Bellatrix ScriptEngine 0.2.0 tcl