Posted to tcl by Poor Yorick at Wed Nov 10 11:33:59 GMT 2021view pretty

package require Thread

proc bg args {
    puts [list {main error handler} $args]
}
interp bgerror {} bg


after 0 {
    interp create t1
    set thread [thread::create]
    thread::send -async $thread {
        proc bg args {
            puts stderr [list {thread error handler} $args]
            flush stderr
        }
        interp bgerror {} bg
    }
    thread::send -async $thread {error {an error}} a
}

vwait forever