Tcl package Thread source code

View Ticket
Login
2021-11-10
21:35 Ticket [5f2922dd6d] interp bgerror is ignored in thread, error sent to other interp instead status still Open with 3 other changes artifact: 478ae04b48 user: pooryorick
13:08 New ticket [5f2922dd6d]. artifact: e05e62fe75 user: pooryorick

Ticket UUID: 5f2922dd6d36f043966bbfff9d5293f8b7c5c121
Title: [interp bgerror] is ignored in thread, error sent to other interp instead
Type: Bug Version:
Submitter: pooryorick Created on: 2021-11-10 13:08:02
Subsystem: - New Builtin Commands Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Open Last Modified: 2021-11-10 21:35:31
Resolution: None Closed By: nobody
    Closed on:
Description:

When the following script is evaluated in a core-8-branch build, the bgerror procedure registered in the "main" interp is called, while the bgerror procedure registered in the "worker" interp is ignored:

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

Output:

an error
    while executing
"error {an error}"
Error from thread tid0x7f0b594fb740
an error
{main error handler} {{an error} {-code 1 -level 0 -errorstack {INNER {invokeStk1 open /home/yorick/opt/tcl_thread--2_branch/lib/tclIndex} CALL auto_load_index} -errorcode NONE -errorinfo {an error} -errorline 1}}

If there is no bgerror procedure in the "main" interp, the bgerror procedure in the "worker" interp is ignored entirely:

package require Thread
 
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

Output:

Error from thread tid0x7f5f12394640
an error
    while executing
"error {an error}"
Error from thread tid0x7f5f12959740
an error
an error