Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tkinter on OSX #4

Open
peanut256 opened this issue Jul 23, 2015 · 4 comments
Open

Tkinter on OSX #4

peanut256 opened this issue Jul 23, 2015 · 4 comments

Comments

@peanut256
Copy link
Contributor

Hi all,

I've successfully compiled JyNI on OSX and none of the unit tests is failing.
But there's trouble with the Tkinter demo: java starts an osx application (with the Tk icon), that shows no window and is not responding at all.

Has anyone experienced the same issue?
I'll look into the problem and try to collect all information about it in this thread.

Best,
Malte

@Stewori
Copy link
Owner

Stewori commented Jul 23, 2015

Hey Malte,
thanks for investigating this! And again big thank you for supplying the OSX-makefile. Unfortunately I currently don't have an OSX-environment available, so I cannot do much on this issue. However I confirmed that it is (probably) not a clang vs gcc issue (note the new clang-makefile for linux). Building JyNI with clang on linux works fine and also the Tkinter-demo works.

Can you figure out the line (in _tkinter.c (?)) where the application is hanging?

Let's strip down the demo to a bare window:

from Tkinter import Tk
root = Tk()
root.mainloop()
print "exit"

Is this already hanging? (I suppose so)

@peanut256
Copy link
Contributor Author

So, it's time for an update in this thread. In case a reader is wondering why it took so long: Stefan and I were working in person on this problem (and others) for some time, and while JyNI is now working really well on OSX, the problem with Tkinter still stands.

As suspected by Stefan, the stripped down version of the demo already freezes on OSX.
A java process with Tk's icon shows up in the Dock, but no window is opened. One can see a window named "Tk" in the window list of the java process (accessible via a ctrl-click in the Dock), but selecting this entry crashes java with a SIGSEGV error.

We could identify the hanging function call in _tkinter.c: it's a call to Tcl_DoOneEvent(0) in line 3036.
In fact, it's always the 7th processed event that causes the freezing.
We have no idea what happens inside of Tcl_DoOneEvent and would appreciate the help of someone who is more familiar with Tk.

PS: We've also looked into OSX specific code in _tkinter.c. There's a call to Tk_MacOSXSetupTkNotifier in init_tkinter(void), protected by an #ifdef TK_AQUA, but this can't be the culprit, since TK_AQUA isn't defined in my configuration (and doing so doesn't help either).

@Stewori
Copy link
Owner

Stewori commented Apr 5, 2016

I prepared the JyNI-unstable repository to debug JyNI regarding _tkinter.c (statically linking it now). I inserted debugging output in _tkinter.c (JyNI-C/src/Modules/_tkinter.c) to log every call to Tk or Tcl-API and every method call in _tkinter.c.

The test tkinter-program JyNI-Demo/src/JyNITkinterTest.py displays a bare tkinter window and I directly clicked the closing button; you can see corresponding closing events at the bottom of the log. So far I did not log Python-part of tkinter (actually wouldn't know where to start).

Malte produced the following output on OSX (hanging run):
https://dl.dropboxusercontent.com/u/50299996/tkinter_log_osx.txt

I produced this log on Linux (LMDE2) (successful run):
https://dl.dropboxusercontent.com/u/50299996/tkinter_log_linux.txt

You will note that they are identical except the OSX one stucks at some point while the linux one continues.

Running the logged tkinter with CPython 2.7.8 on Linux produces this output:
https://dl.dropboxusercontent.com/u/50299996/tkinter_log_linux-CPython2.7.txt

Only difference to JyNI-run is that it skips these calls that were present in the JyNI-log:

Tcl_AppInit (680)
683: Tcl_Init(interp)
689: Tcl_GetVar(interp, "_tkinter_skip_tk_init", TCL_GLOBAL_ONLY)
702: Tk_Init(interp)

Another thing we tried was to call Tcl_DoOneEvent(0) in line 3049 with TCL_DONT_WAIT. This crashes Java on OSX while it runs fine on Linux (with an infinit background loop though). We are currently debugging this issue (probably another uninitialized memory thing). JyNI-unstable/TCL_DONT_WAIT branch is about this topic. However I suspect the TCL_DONT_WAIT-triggered crash is a separate issue.

Any hints (how to debug the original issue) appreciated.

@rndblnch
Copy link

rndblnch commented Apr 5, 2016

Tcl_DoOneEvent calls Tcl_WaitForEvent which is platform specific (see macosx/tclMacOSXNotify.c at
http://core.tcl.tk/tcl/artifact/c699f984689dd959 ).
You will need help from people knowing tcl and macosx internals…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants