From: Steve L. <st...@di...> - 2017-12-03 00:42:58
|
Tk 8.6.6 but also happens with 8.6.4. Both running on MacOS HIgh Sierra 10.13.2 Beta. I fully understand that the received wisdom is that Tk should only be run on the main thread, but this is the first time I have ever encountered it not working. Time for a documentation update methinks. —Steve On 2 Dec 2017, 11:05 AM +0800, Marc Culler <mar...@gm...>, wrote: > You don't say which version of Tk you are using, or which version of macOS, but when I run your script using the current leaf of the core-8-6-branch on my Sierra system I get a small window with a label inside which says "this is a label". > > That is not to say that all is well with your script. Wish crashes with a segfault when the small window is closed. But it is far from clear to me how that crash is related to the process of "running Tk on a child thread". > > It helps, when discussing problems like this, to try to be extremely precise with your language. When Jim says "You are not supposed to use AppKit (underlying Tk on macOS) on anything but the main thread" I think he probably means that you are not supposed to call any methods of the NSApplication object from threads other than the main thread. Presumably that is also true for objects like NSView or NSWindow, although in many cases methods of those objects are necessarily called from the same thread as the NSApplication methods. But is that happening here? Maybe. However, the fact that a Tk interpreter is running in a child thread does not imply that any NSApp methods are being executed in that child. It would surely be possible for the event queue of an interpreter running in a child thread to be shared with the main thread, and for the actual calls to NSApplication methods to be executed by the main thread. Whether that is happening in this case depends on how the Threads package is implemented. It will not be possible to understand what is actually going on without doing some serious debugging work. Slogans don't suffice. > > It also is essential for everyone involved in a discussion of a problem like this to be running in the same environment. Would you please try running your script in the current leaf of the core-8-6-branch? > > - Marc > > > On Fri, Dec 1, 2017 at 3:58 PM, Steve Landers <st...@di...> wrote: > > > My experience is in iOS, where Xcode will warn you but still run the resulting program. Best practice is definitely to run on the default queue (a.k.a. main thread). I suspect that at some point in the future this will be a runtime error. > > > > > > Back to Tk, my question is whether Tk on MacOS should print a warning or throw an error if run on a child thread? And, if so, does that mean MacOS Tk diverges from other platforms like Windows and Linux. Or should all platforms be consistent? > > > > > > At very least the documentation should mention the MacOS restriction, but where in the documentation? > > > > > > Steve > > > > > > On 2 Dec 2017, 2:20 AM +0800, Jim Ingham <ji...@ap...>, wrote: > > > > 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 > > > > > > > > > > > > > On Dec 1, 2017, at 6:03 AM, Programmingkid <pro...@gm...> wrote: > > > > > > > > > > > > > > > > > On Dec 1, 2017, at 1:30 AM, Steve Landers <st...@di...> wrote: > > > > > > > > > > > > Should Tk work in a thread on MacOS ? > > > > > > > > > > > > The following script works on Linux and Windows, but not MacOS the toplevel window resizes but the label doesn’t appear. > > > > > > > > > > > > I can’t find any documentation that says it shouldn’t work. > > > > > > package require Thread > > > > > > set id [thread::create] > > > > > > thread::send $id { > > > > > > package require Tk > > > > > > label .l1 -text "This is a label" > > > > > > grid configure .l1 > > > > > > } > > > > > > > > > > > > It seems the grid is the problem, because I can see the label widget exists. Replacing grid with a pack doesn’t fix it. > > > > > > > > > > > > Can anyone shed some light? > > > > > > > > > > > > —Steve > > > > > > > > > > It is common for GUI frameworks to only want to use the main thread for all their GUI work. > > > > > > > > > > When I tried out your code in wish I saw the label, so it works for me. Only when I tried quitting the application an exception occurred. > > > > > > > > > > My info: > > > > > TK 8.5.9 > > > > > Mac OS 10.12.6 > > > > > ------------------------------------------------------------------------------ > > > > > Check out the vibrant tech community on one of the world's most > > > > > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > > > > > _______________________________________________ > > > > > Tcl-mac mailing list > > > > > tc...@li... > > > > > https://lists.sourceforge.net/lists/listinfo/tcl-mac > > > > > > > > > > > > ------------------------------------------------------------------------------ > > > > Check out the vibrant tech community on one of the world's most > > > > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > > > > _______________________________________________ > > > > Tcl-mac mailing list > > > > tc...@li... > > > > https://lists.sourceforge.net/lists/listinfo/tcl-mac > > > > > > ------------------------------------------------------------------------------ > > > Check out the vibrant tech community on one of the world's most > > > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > > > _______________________________________________ > > > Tcl-mac mailing list > > > tc...@li... > > > https://lists.sourceforge.net/lists/listinfo/tcl-mac > > > > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Tcl-mac mailing list > tc...@li... > https://lists.sourceforge.net/lists/listinfo/tcl-mac |