This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Tkinter-related segfault on macOS (regression between 3.7.0 and 3.7.1rc1)
Type: Stage: resolved
Components: Tkinter Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ned.deily Nosy List: aivarannamaa, ned.deily, xtreak
Priority: normal Keywords:

Created on 2018-10-08 07:32 by aivarannamaa, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (12)
msg327326 - (view) Author: Aivar Annamaa (aivarannamaa) Date: 2018-10-08 07:32
After switching from Python 3.7.0 to 3.7.1rc1 (macOS, 64-bit only downloaded from python.org), my rather big Tkinter application started to segfault whenever I close a system dialog (eg. the one created by askopenfilename or showerror) by keypress (eg. Escape or Enter). The crash does not happen when I close the dialog with mouse click.

The code that calls the dialog runs fine, and the crash seems to happen next time the control goes back to Tk mainloop. It looks like the keypress performed in the dialog somehow remains in Tk event queue.

Here is the system log for main thread, (more detailed information can be seen at https://bitbucket.org/plas/thonny/issues/545/quit):

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

VM Regions Near 0:
--> 
    __TEXT                 000000010ab7e000-000000010ab7f000 [    4K] r-x/rwx SM=COW  /Users/USER/Desktop/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fff97e1a8ea __kill + 10
1   libsystem_platform.dylib        0x00007fff96dba52a _sigtramp + 26
2   ???                             000000000000000000 0 + 0
3   libtk8.6.dylib                  0x000000010b876e84 -[TKApplication(TKKeyEvent) tkProcessKeyEvent:] + 160
4   libtk8.6.dylib                  0x000000010b87d6d9 TkMacOSXEventsCheckProc + 360
5   libtcl8.6.dylib                 0x000000010b714d06 Tcl_DoOneEvent + 316
6   _tkinter.cpython-37m-darwin.so  0x000000010b64501d _tkinter_tkapp_mainloop + 269
7   org.python.python               0x000000010aba752e _PyMethodDef_RawFastCallKeywords + 430
8   org.python.python               0x000000010abad192 _PyMethodDescr_FastCallKeywords + 82
9   org.python.python               0x000000010ac6640c call_function + 780
10  org.python.python               0x000000010ac6339c _PyEval_EvalFrameDefault + 25164
11  org.python.python               0x000000010ac66f06 _PyEval_EvalCodeWithName + 2422
12  org.python.python               0x000000010aba6a61 _PyFunction_FastCallKeywords + 257
13  org.python.python               0x000000010ac663e2 call_function + 738
14  org.python.python               0x000000010ac633b6 _PyEval_EvalFrameDefault + 25190
15  org.python.python               0x000000010aba6ed0 function_code_fastcall + 128
16  org.python.python               0x000000010ac663e2 call_function + 738
17  org.python.python               0x000000010ac63457 _PyEval_EvalFrameDefault + 25351
18  org.python.python               0x000000010ac66f06 _PyEval_EvalCodeWithName + 2422
19  org.python.python               0x000000010ac5d074 PyEval_EvalCode + 100
20  org.python.python               0x000000010ac5a65d builtin_exec + 557
21  org.python.python               0x000000010aba752e _PyMethodDef_RawFastCallKeywords + 430
22  org.python.python               0x000000010aba6a9a _PyCFunction_FastCallKeywords + 42
23  org.python.python               0x000000010ac663d4 call_function + 724
24  org.python.python               0x000000010ac63457 _PyEval_EvalFrameDefault + 25351
25  org.python.python               0x000000010ac66f06 _PyEval_EvalCodeWithName + 2422
26  org.python.python               0x000000010aba6a61 _PyFunction_FastCallKeywords + 257
27  org.python.python               0x000000010ac663e2 call_function + 738
28  org.python.python               0x000000010ac63457 _PyEval_EvalFrameDefault + 25351
29  org.python.python               0x000000010ac66f06 _PyEval_EvalCodeWithName + 2422
30  org.python.python               0x000000010aba663b _PyFunction_FastCallDict + 523
31  org.python.python               0x000000010acb8743 pymain_run_module + 147
32  org.python.python               0x000000010acb7b47 pymain_main + 5303
33  org.python.python               0x000000010acb868a _Py_UnixMain + 58
34  libdyld.dylib                   0x00007fff921c35ad start + 1
msg327327 - (view) Author: Aivar Annamaa (aivarannamaa) Date: 2018-10-08 07:33
Here is a simple application that also exposes this problem. Click at the button and press Escape when dialog appears.

import tkinter as tk
import tkinter.filedialog as fd
 
root = tk.Tk()
 
def dostuff():
    fd.askopenfile()
 
bt = tk.Button(root, text="Click me!", command=dostuff)
bt.grid()
 
root.mainloop()
msg327328 - (view) Author: Aivar Annamaa (aivarannamaa) Date: 2018-10-08 07:42
Looks like the workaround is to provide explicit `parent` named argument to the dialog call.
msg327329 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-10-08 07:55
Thanks for the report and script. I can't reproduce this with 3.7.1rc1 tag and also tried this on v3.7.0 which works fine on Mac OS running 10.10.4 and tcl version 8.5 . I checked out the 3.7.1rc1 tag and did a clean rebuild with `git clean -xdf && ./configure --with-pydebug && make -s -j4` and tried below

Steps I followed : 

* I executed the script.
* clicked on "click me" button.
* A file open dialog opened and I closed this with esc.
* Again clicked "click me" button and selected a file to click enter the file open dialog disappeared 
* Closed the main box with "click me". No segfault.

Since the report says it's a regression between 3.7.0 and 3.7.1RC1 I am adding Ned as a friendly ping about this issue so that this can be tracked better between RC releases.
msg327330 - (view) Author: Aivar Annamaa (aivarannamaa) Date: 2018-10-08 08:12
I got the segfault with Tk 8.6, provided with python.org installer.
msg327331 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-10-08 08:41
Thanks, I can confirm that this works with 3.7.0 and segfaults with 3.7.1RC1 Mac OS installer that uses Tk 8.6 . Clicking the button and closing the file open dialog triggers this segfault as noted in your description. I don't know how I can configure my local build to use Tk 8.6 and maybe it's a problem with Tk 8.6. It seems from 3.7 and above the installer uses 8.6 while 3.6 dynamically links to the apple's version 8.5 as noted in https://www.python.org/download/mac/tcltk/#built-in-8-6-8
msg327332 - (view) Author: Aivar Annamaa (aivarannamaa) Date: 2018-10-08 09:09
Can it be caused by https://github.com/python/cpython/commit/adf493227f1efd5d6b34f46b854142bf3b5a411c ?
msg327333 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-08 09:13
> Can it be caused by https://github.com/python/cpython/commit/adf493227f1efd5d6b34f46b854142bf3b5a411c ?

It very likely could be.  Thanks for the report.  I'll take a look at it a bit later.
msg327668 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-13 20:39
New changeset f55c3ae657595d12ce78aca76c9c6b998d632424 by Ned Deily in branch '3.6':
bpo-34370: Revert to using released Tk 8.6.8 with macOS installers
https://github.com/python/cpython/commit/f55c3ae657595d12ce78aca76c9c6b998d632424
msg327670 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-13 20:46
New changeset d8b6425e58a1fccdf8ddbbcde63066c13c1bcfaf by Ned Deily in branch '3.7':
bpo-34370: Revert to using released Tk 8.6.8 with macOS installers
https://github.com/python/cpython/commit/d8b6425e58a1fccdf8ddbbcde63066c13c1bcfaf
msg327687 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-14 02:02
It appears that the segfault behavior *was* introduced by some change in the Tk 8.6 development snapshot I chose to use for the python.org macOS installer builds in 3.7.1rc1 and 3.6.7rc2.  For 3.7.1rc2 and 3.6.7rc2, I reverted back to using the standard Tk 8.6.8 release and the segfault seems to have gone away on the systems where I was able to reproduce it with rc1 - whether it segfaulted seems to be system dependent.  We'll probably wait for the official release of Tk 8.6.9 before trying to upgrade Tk again.  Let us know if the problem reappears.
msg327692 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-10-14 06:13
Thanks for the release Ned. I can confirm that there is no segfault with Python 3.7.1rc2 (v3.7.1rc2:6c06ef7dc3).
History
Date User Action Args
2022-04-11 14:59:06adminsetgithub: 79108
2018-10-14 06:13:14xtreaksetmessages: + msg327692
2018-10-14 02:02:39ned.deilysetstatus: open -> closed
resolution: fixed
messages: + msg327687

stage: resolved
2018-10-13 20:46:38ned.deilysetmessages: + msg327670
2018-10-13 20:39:49ned.deilysetmessages: + msg327668
2018-10-08 09:13:06ned.deilysetassignee: ned.deily
messages: + msg327333
2018-10-08 09:09:35aivarannamaasetmessages: + msg327332
2018-10-08 08:41:49xtreaksetmessages: + msg327331
2018-10-08 08:12:43aivarannamaasetmessages: + msg327330
2018-10-08 07:55:01xtreaksetnosy: + ned.deily, xtreak
messages: + msg327329
2018-10-08 07:42:51aivarannamaasetmessages: + msg327328
2018-10-08 07:33:34aivarannamaasetmessages: + msg327327
2018-10-08 07:32:02aivarannamaacreate