classification
Title: Crash with tkinter text on osx
Type: Stage: resolved
Components: Tkinter Versions: Python 3.7
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: ned.deily, remi_bertholet, xtreak
Priority: normal Keywords:

Created on 2018-11-10 10:56 by remi_bertholet, last changed 2018-11-12 04:38 by ned.deily. This issue is now closed.

Files
File name Uploaded Description Edit
ScrollFrame.py remi_bertholet, 2018-11-10 10:56
Messages (9)
msg329606 - (view) Author: remi bertholet (remi_bertholet) Date: 2018-11-10 10:56
Hello,

If I press the key "Alt-Shift-F" with script it crash all times. I reproduces the same crash with Python 2.7. 
To reproduce it, on terminal osx 10.13.6 (17G3025) : 
- run "python3 ScrollFrame.py" 
- Click one time on tk window (it show on foreground)
- Press "Ctrl-Alt-F" (all other alt produce the same crash)
- And you obtain the crash next :

The crash on python 3.7 :

2018-11-10 11:50:30.702 Python[3095:292595] *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFConstantString characterAtIndex:]: Range or index out of bounds'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff2b04123b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x00007fff522d2c76 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff2b0d2d5d +[NSException raise:format:] + 205
	3   CoreFoundation                      0x00007fff2afbd236 -[__NSCFString characterAtIndex:] + 102
	4   Tk                                  0x00007fff37721343 TkpInitKeymapInfo + 731
	5   Tk                                  0x00007fff377271a1 Tk_MacOSXSetupTkNotifier + 798
	6   Tcl                                 0x00007fff37621a50 Tcl_DoOneEvent + 300
	7   _tkinter.cpython-37m-darwin.so      0x000000010dd957ac _tkinter_tkapp_mainloop + 256
	8   Python                              0x000000010d3d4f42 _PyMethodDef_RawFastCallKeywords + 525
	9   Python                              0x000000010d3d981e _PyMethodDescr_FastCallKeywords + 82
	10  Python                              0x000000010d46b1a2 call_function + 615
	11  Python                              0x000000010d4622ec _PyEval_EvalFrameDefault + 2579
	12  Python                              0x000000010d46bad1 _PyEval_EvalCodeWithName + 1837
	13  Python                              0x000000010d3d4474 _PyFunction_FastCallKeywords + 225
	14  Python                              0x000000010d46b17a call_function + 575
	15  Python                              0x000000010d462305 _PyEval_EvalFrameDefault + 2604
	16  Python                              0x000000010d46bad1 _PyEval_EvalCodeWithName + 1837
	17  Python                              0x000000010d461851 PyEval_EvalCode + 42
	18  Python                              0x000000010d490a5f run_mod + 54
	19  Python                              0x000000010d48fa7a PyRun_FileExFlags + 164
	20  Python                              0x000000010d48f159 PyRun_SimpleFileExFlags + 283
	21  Python                              0x000000010d4a6842 pymain_main + 5114
	22  Python                              0x000000010d4a6fd4 _Py_UnixMain + 104
	23  libdyld.dylib                       0x00007fff52eec015 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6

The crash on python 2.7 :

2018-11-10 11:51:34.728 Python[3104:294757] *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFConstantString characterAtIndex:]: Range or index out of bounds'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff2b04123b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x00007fff522d2c76 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff2b0d2d5d +[NSException raise:format:] + 205
	3   CoreFoundation                      0x00007fff2afbd236 -[__NSCFString characterAtIndex:] + 102
	4   Tk                                  0x00007fff37721343 TkpInitKeymapInfo + 731
	5   Tk                                  0x00007fff377271a1 Tk_MacOSXSetupTkNotifier + 798
	6   Tcl                                 0x00007fff37621a50 Tcl_DoOneEvent + 300
	7   _tkinter.so                         0x00000001026cca77 Tkapp_MainLoop + 354
	8   Python                              0x000000010236a357 PyEval_EvalFrameEx + 19822
	9   Python                              0x00000001023653d2 PyEval_EvalCodeEx + 1562
	10  Python                              0x000000010236e4d7 fast_function + 290
	11  Python                              0x000000010236a25a PyEval_EvalFrameEx + 19569
	12  Python                              0x00000001023653d2 PyEval_EvalCodeEx + 1562
	13  Python                              0x0000000102364db2 PyEval_EvalCode + 32
	14  Python                              0x000000010238679b run_mod + 49
	15  Python                              0x0000000102386842 PyRun_FileExFlags + 130
	16  Python                              0x00000001023863c4 PyRun_SimpleFileExFlags + 706
	17  Python                              0x0000000102397f44 Py_Main + 3136
	18  libdyld.dylib                       0x00007fff52eec015 start + 1
	19  ???                                 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6
msg329609 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-11-10 14:26
Thanks for the report. I added Ned since it seemed similar to issue32481 but  from Python 3.7 the Mac installers from python.org ship with in-built Tcl/Tk 8.6.8 as in which was the reported version https://www.python.org/download/mac/tcltk/#built-in-8-6-8 . I was able to reproduce the crash with attached file on 3.6 which was installed from Homebrew. I was not able to reproduce the crash on Python 3.7.1RC2 installed from python.org. I don't know if installing 3.7 from Homebrew might cause problems with my existing virtual environments to validate my assumption.

1. @remi_bertholet Is Python 3.7 installed with Homebrew? 
2. Ned, does Python 3.7 that is installed from Homebrew ship with in-built Tcl/Tk similar to Mac installers from python.org?
msg329611 - (view) Author: remi bertholet (remi_bertholet) Date: 2018-11-10 14:42
Yes I use homebrew.

I have done :
brew update
brew upgrade

python 3.7.1 installed :
Python 3.7.1 (default, Nov  6 2018, 18:45:35)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

but I still have the crash with this version :

2018-11-10 15:37:54.784 Python[35388:488345] *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFConstantString characterAtIndex:]: Range or index out of bounds'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff2b04123b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x00007fff522d2c76 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff2b0d2d5d +[NSException raise:format:] + 205
	3   CoreFoundation                      0x00007fff2afbd236 -[__NSCFString characterAtIndex:] + 102
	4   Tk                                  0x00007fff37721343 TkpInitKeymapInfo + 731
	5   Tk                                  0x00007fff377271a1 Tk_MacOSXSetupTkNotifier + 798
	6   Tcl                                 0x00007fff37621a50 Tcl_DoOneEvent + 300
	7   _tkinter.cpython-37m-darwin.so      0x0000000106b877ab _tkinter_tkapp_mainloop + 256
	8   Python                              0x00000001061e3313 _PyMethodDef_RawFastCallKeywords + 496
	9   Python                              0x00000001061e7caa _PyMethodDescr_FastCallKeywords + 82
	10  Python                              0x0000000106278bd0 call_function + 801
	11  Python                              0x0000000106271758 _PyEval_EvalFrameDefault + 6991
	12  Python                              0x0000000106279432 _PyEval_EvalCodeWithName + 1835
	13  Python                              0x00000001061e2874 _PyFunction_FastCallKeywords + 225
	14  Python                              0x0000000106278ba0 call_function + 753
	15  Python                              0x0000000106271771 _PyEval_EvalFrameDefault + 7016
	16  Python                              0x0000000106279432 _PyEval_EvalCodeWithName + 1835
	17  Python                              0x000000010626fb81 PyEval_EvalCode + 42
	18  Python                              0x000000010629e6ed run_mod + 54
	19  Python                              0x000000010629d708 PyRun_FileExFlags + 164
	20  Python                              0x000000010629cdc2 PyRun_SimpleFileExFlags + 266
	21  Python                              0x00000001062b4adc pymain_main + 5665
	22  Python                              0x00000001062b50ff _Py_UnixMain + 75
	23  libdyld.dylib                       0x00007fff52eec015 start + 1
	24  ???                                 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException

> Le 10 nov. 2018 à 15:26, Karthikeyan Singaravelan <report@bugs.python.org> a écrit :
> 
> 
> Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment:
> 
> Thanks for the report. I added Ned since it seemed similar to issue32481 but  from Python 3.7 the Mac installers from python.org ship with in-built Tcl/Tk 8.6.8 as in which was the reported version https://www.python.org/download/mac/tcltk/#built-in-8-6-8 . I was able to reproduce the crash with attached file on 3.6 which was installed from Homebrew. I was not able to reproduce the crash on Python 3.7.1RC2 installed from python.org. I don't know if installing 3.7 from Homebrew might cause problems with my existing virtual environments to validate my assumption.
> 
> 1. @remi_bertholet Is Python 3.7 installed with Homebrew? 
> 2. Ned, does Python 3.7 that is installed from Homebrew ship with in-built Tcl/Tk similar to Mac installers from python.org?
> 
> ----------
> nosy: +xtreak
> 
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue35209>
> _______________________________________
msg329615 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-11-10 14:54
Thanks, can you please try the mac installer from python.org to see if the crash is till present : https://www.python.org/downloads/release/python-371/

Please remove the original email content while replying from email unless the relevant parts need to be quoted. The content is added to the tracker making the reply hard to read.
msg329617 - (view) Author: remi bertholet (remi_bertholet) Date: 2018-11-10 15:01
with the python installer I do not have the problem...
msg329620 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-11-10 15:05
Thanks a lot remi_bertholet. I think this is related to issue32481 . I will wait for Ned's confirmation on how Homebrew packages Python 3.7 with Tcl/Tk and if it's different from python.org Mac installers.
msg329628 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-11-10 17:15
Thanks for the report and for the investigation. The Tk crash described in Issue32481 (and many other earlier issues) is due to a very old bug in Tk 8.5.x for macOS.  While this bug has been fixed in more recent versions of 8.5.x and in 8.6.x, the version of Tk shipped by Apple with macOS has not been updated since Mac OS X 10.7 (!) and so apps that use it will see this crash.  Which Tk a particular instance of Python tkinter will link with depends on how that Python was built.  In general, there are ways to check which one is in use.  The easiest is, when the app is running, go to the macOS menu bar, select the app name (the second menu row which, for standalone Python scripts will likely be labeled "Python"), then choose the first menu item under it, the "About <app name>" item.  Unless the app itself has defined its own About menu (like IDLE.app does) that should bring up a Tk app window that says what version of Tk is running.  (The IDLE.app About window also says what version of Tk is in use.)  If the version is 8.5.9, the app is most likely using the buggy system Tk.  It's also possible for the Python program to get the Tk version in-use at runtime; see tkVersionWarning in IDLE for an example:

https://github.com/python/cpython/blob/v3.7.1/Lib/idlelib/macosx.py#L69

An even more definite confirmation is to examine the macOS crash report produced (either on screen or saved at ~/Library/Logs/DiagnosticReports and browsable with Console.app).  Search the Binary Images section for the specific Tk file name in use.  If the line found has Tk (8.5.9 - 8.5.9) and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk in it, you know that the culprit is the Apple-supplied Tk.  If the file name is something else, like /Library/Frameworks/Tk.framework/Versions/8.5/Tk, then the system Tk is not to blame.


There is more info here:
https://www.python.org/download/mac/tcltk/
msg329669 - (view) Author: remi bertholet (remi_bertholet) Date: 2018-11-11 07:47
The problem is due to an old version of tk. I deleted the python3 from homebrew. With version 3.7.1 python.org, the crash is no longer, but the keyboard shortcuts tkinter on the menus (accelerator), seems to be capricious, they work once, then it does not work anymore. I did not have this problem before, is it a regression of version 3.7.1?
msg329711 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-11-12 04:38
Good to hear you have worked around the crash.  Regarding keyboard accelerators, I'm not aware of any 3.7.1 regressions but there could be issues with the bundled version of Tk 8.6.8.  If you want to pursue the issue, please supply a test case that demonstrates the misbehavior and reopen this issue.
History
Date User Action Args
2018-11-12 04:38:03ned.deilysetstatus: open -> closed
resolution: third party
messages: + msg329711

stage: resolved
2018-11-11 07:47:10remi_bertholetsetmessages: + msg329669
2018-11-10 17:15:29ned.deilysetmessages: + msg329628
2018-11-10 15:05:14xtreaksetmessages: + msg329620
2018-11-10 15:01:00remi_bertholetsetmessages: + msg329617
2018-11-10 14:54:48xtreaksetmessages: + msg329615
2018-11-10 14:42:30remi_bertholetsetmessages: + msg329611
2018-11-10 14:26:06xtreaksetnosy: + xtreak
messages: + msg329609
2018-11-10 11:32:19xtreaksetnosy: + ned.deily
2018-11-10 10:56:38remi_bertholetcreate