| Ticket UUID: | 25cb062bda7dac7d893cf14755e135fc05c87ff9 | |||
| Title: | Allow Tk to be run in a child thread on MacOS | |||
| Type: | Bug | Version: | 8.7 | |
| Submitter: | anonymous | Created on: | 2017-12-01 19:42:26 | |
| Subsystem: | 83. Mac OS X Build | Assigned To: | nobody | |
| Priority: | 5 Medium | Severity: | Important | |
| Status: | Open | Last Modified: | 2018-07-26 14:52:45 | |
| Resolution: | None | Closed By: | nobody | |
| Closed on: | ||||
| Description: |
On MacOS 10.13.2 starting Tk in a child thread causes Tk grid and pack to not work correctly, unlike on Windows and Linux. While widgets such as label can be created and manipulated, neither grid nor pack cause them to be displayed.
This script demonstrates the problem - the toplevel remains empty.
package require Thread
set id [thread::create]
thread::send $id {
package require Tk
label .l1 -text "This is a label"
grid configure .l1
}
While the actual GUI framework calls should be run on the main thread (strictly speaking, on the Grand Central Dispatch main queue) there is no reason why the Tk code cannot run on a single child thread so long as the GUI API calls are made on the main queue.
| |||
| User Comments: |
aspect added on 2018-07-26 14:52:45:
I had the same problem Steve's 2017-12-04 comment with tksh, to do with loading Tk in multiple threads. There I worked around it by using `load "" Tk` in the child thread, after the master had done `package require Tk`. See https://chiselapp.com/user/aspect/repository/snot/tktview/0c65cfc14f This probably has no bearing on the original issue, but might offer a workaround. stevel added on 2017-12-05 05:44:37: I’ve now built using core-8-6-branch and I now see the same behaviour as Marc. This is good, it means the problem I saw isn’t due to the High Sierra 10.13.2 beta. Given I was previously testing using Tcl 8.6.7 via a tclkit it may be there is something in the tclkit startup that was causing the problem I saw. I also see the segmentation fault when I kill the toplevel window. Also on one occasion I did see a problem … $ wish tst.tcl Assertion failed: (s->stack->next != NULL), function CGGStackRestore, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/Quartz2D/Quartz2D-1129.5/CoreGraphics/Context/CGGStack.c, line 77. /opt/local/bin/wish: line 2: 27141 Abort trap: 6 "$(dirname $0)/../../../Library/Frameworks/Tk.framework/Versions/8.6/Resources/Wish.app/Contents/MacOS/Wish" "$@" I suspect there’s a timing related problem because I can’t reproduce it. marc_culler added on 2017-12-04 16:50:38: When I test this script using checkout [b86509615] on either OS X 10.12.2 or 10.13 I see different behavior. The toplevel properly displays the label. Running 'package require Tk' in the main thread after running it in the child thread does not generate any warning messages about event queues. However, when the toplevel containing the label is closed I get a segfault with a stacktrace that starts like this: 0 Tk 0x000000010a41a696 Tk_DestroyWindow + 214 1 Tk 0x000000010a3ffd84 Tk_HandleEvent + 1205 2 Tk 0x000000010a4b25ea TkGenWMDestroyEvent + 116 3 Tk 0x000000010a4b253b 0x10a3eb000 + 816443 4 com.apple.AppKit 0x00007fffa0f2890a __19-[NSWindow __close]_block_invoke + 124 5 com.apple.AppKit 0x00007fffa0f28881 -[NSWindow __close] + 305 6 libsystem_trace.dylib 0x00007fffb8ac33a7 _os_activity_initiate_impl + 53 7 com.apple.AppKit 0x00007fffa1380721 -[NSApplication(NSResponder) sendAction:to:from:] + 456 8 com.apple.AppKit 0x00007fffa0e64cc4 -[NSControl sendAction:to:] + 86 9 com.apple.AppKit 0x00007fffa0e64bec __26-[NSCell _sendActionFrom:]_block_invoke + 136 10 libsystem_trace.dylib 0x00007fffb8ac33a7 _os_activity_initiate_impl + 53 11 com.apple.AppKit 0x00007fffa0e64b44 -[NSCell _sendActionFrom:] + 128 12 com.apple.AppKit 0x00007fffa0ea7539 -[NSButtonCell _sendActionFrom:] + 98 stevel added on 2017-12-04 07:32:46: One other data point, running "package require Tk" in a child thread then running it again in the main thread causes the following error to be displayed. % package require Tk 8.6.7 % 2017-12-03 13:02:40.315 tclkit[4291:126150] !!! BUG: The current event queue and the main event queue are not the same. Events will not be handled correctly. This is probably because _TSGetMainThread was called for the first time off the main thread. stevel added on 2017-12-04 07:29:05: As per email from on [email protected] MACTCL mailing list: You are not supposed to use AppKit (underlying Tk on macOS) on anything but the main thread. The Xcode team even added a "Main Thread Checker" tool in the latest version of Xcode to flag uses of AppKit not on the main thread: https://developer.apple.com/documentation/code_diagnostics/main_thread_checker Jim | |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki