Tk Source Code

View Ticket
Login
Ticket UUID: 35e67b8124de90cff3e7f54d4407ebb6b14e8513
Title: tk sysnotify crashes after the interpreter which used it was deleted
Type: Bug Version: 9.0.5, trunk
Submitter: serhiy.storchaka Created on: 2026-09-18 16:14:34
Subsystem: -- New Commands Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Severe
Status: Pending Last Modified: 2026-10-08 17:18:38
Resolution: Fixed Closed By: nobody
    Closed on:
Description:

On X11 with libnotify, tk sysnotify crashes (9.0.5) or hangs (trunk) when it is called in a new interpreter after the last interpreter which used it was deleted:

foreach name {i j} {
    interp create $name
    $name eval {package require Tk; tk sysnotify "Tk test" "test notification"}
    interp delete $name
}
(tclsh9.0): GLib-GObject-CRITICAL **: cannot register existing type 'NotifyNotification'
...
Segmentation fault (core dumped)

SysNotifyDeleteCmd() in unix/tkUnixSysNotify.c unloads libnotify when the last interpreter is deleted. But libnotify registers GObject types, which cannot be unregistered, so loading it again fails: notify_notification_new() returns NULL and notify_notification_show() crashes.

The fix on branch [sysnotify-no-unload] keeps libnotify loaded for the lifetime of the process; only notify_uninit() is called when the last interpreter is deleted.

Found by Python's tkinter test suite: https://github.com/python/cpython/pull/157760

User Comments: serhiy.storchaka added on 2026-10-08 17:18:38:

The test was wrong, not the fix. The child interpreters loaded Tk with package require Tk, which only works if Tk is installed, and the test assumed that libnotify is loaded, which is not the case without libnotify; on Windows and macOS tk sysnotify does not use libnotify at all. Branch sysnotify-test-libnotify loads Tk in the child interpreters as in the main one, and runs the test only on X11 with libnotify loaded (constraint libnotify instead of unix knownBug). It passes with the fix on X11 and is skipped on Windows; without the fix the test hangs. Not tested on macOS.


jan.nijtmans added on 2026-10-08 16:12:52:

Merged to [daa6f8f5ec296052|trunk] and core-9-0-branch

Keeping 'Pending' because of the failing testcase


jan.nijtmans added on 2026-10-08 16:10:32:

I'm seeing the new testcase for this ticket failing on macOS and x11:

==== sysnotify-3 libnotify is not unloaded when the last interpreter which used it is deleted - bug 35e67b8124 FAILED
==== Contents of test case:
    exec [interpreter] <$script
---- Test generated error; Return code was: 1
---- Return code should have been one of: 0 2
---- errorInfo: ok
can't delete "::tk::sysnotify::_sysnotify": command doesn't exist
can't find package Tk
    while executing
"exec [interpreter] <$script"
    ("uplevel" body line 2)
    invoked from within
"uplevel 1 $script"
---- errorCode: NONE
==== sysnotify-3 FAILED

For now, disabling this testcase