classification
Title: Using tkinter.filedialog crashes on macOS Python 3.9.6
Type: crash Stage:
Components: macOS, Tkinter Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Marc.Culler, Nythepegasus, culler, enki1711, epaine, guydestefano, i3p9, mlierley, ned.deily, ronaldoussoren, serhiy.storchaka, wordtech
Priority: normal Keywords: patch

Created on 2021-08-04 11:21 by Nythepegasus, last changed 2021-10-11 18:31 by guydestefano.

Files
File name Uploaded Description Edit
tkinter_crash.py Nythepegasus, 2021-08-04 11:21 The bit of code that crashes when ran on an M1 Mac running macOS 12.0 Beta (21A5294g)
Screen Shot 2021-08-29 at 7.44.33 PM.png mlierley, 2021-08-30 02:45 Error and System info
openfile.patch culler, 2021-10-11 12:37 patch to revert to [NSApp runModalForWindow:] on Monterery and later
Messages (21)
msg398889 - (view) Author: Nythepegasus (Nythepegasus) Date: 2021-08-04 11:21
Using tkinter.filedialog crashes on macOS 12.0 Beta (21A5294g) on M1 when the open file dialog window is created. Full crash below:

2021-08-04 07:19:04.239 Python[40251:323363] *** Assertion failure in -[NSOpenPanel beginServicePanel:asyncExHandler:], NSVBOpenAndSavePanels.m:1910
2021-08-04 07:19:04.241 Python[40251:323363] -[NSSavePanel beginWithCompletionHandler:]_block_invoke caught non-fatal NSInternalInconsistencyException '<NSOpenPanel: 0x1206062d0> is attempting to advance this Open/Save panel to run phase while another self.advanceToRunPhaseCompletionHandler is in waiting for a previous attempt. An Open/Save panel cannot start to advance more than once.' with user dictionary {
    NSAssertFile = "NSVBOpenAndSavePanels.m";
    NSAssertLine = 1910;
} and backtrace (
	0   CoreFoundation                      0x00000001a9d47150 __exceptionPreprocess + 240
	1   libobjc.A.dylib                     0x00000001a9a986e8 objc_exception_throw + 60
	2   Foundation                          0x00000001aac3b4a4 -[NSCalendarDate initWithCoder:] + 0
	3   AppKit                              0x00000001ad1f02b0 -[NSSavePanel beginServicePanel:asyncExHandler:] + 512
	4   AppKit                              0x00000001ad1f1708 -[NSSavePanel runModal] + 332
	5   libtk8.6.dylib                      0x00000001013d8c18 showOpenSavePanel + 360
	6   libtk8.6.dylib                      0x00000001013d99e4 Tk_ChooseDirectoryObjCmd + 992
	7   libtcl8.6.dylib                     0x00000001011cbafc TclNRRunCallbacks + 80
	8   _tkinter.cpython-39-darwin.so       0x0000000100c111a4 Tkapp_Call + 400
	9   Python                              0x0000000100d66a40 cfunction_call + 96
	10  Python                              0x0000000100d184e0 _PyObject_Call + 128
	11  Python                              0x0000000100e10150 _PyEval_EvalFrameDefault + 40288
	12  Python                              0x0000000100e053f0 _PyEval_EvalCode + 444
	13  Python                              0x0000000100d1877c _PyFunction_Vectorcall + 364
	14  Python                              0x0000000100e12590 call_function + 128
	15  Python                              0x0000000100e0ff08 _PyEval_EvalFrameDefault + 39704
	16  Python                              0x0000000100e053f0 _PyEval_EvalCode + 444
	17  Python                              0x0000000100d1877c _PyFunction_Vectorcall + 364
	18  Python                              0x0000000100e12590 call_function + 128
	19  Python                              0x0000000100e0ff84 _PyEval_EvalFrameDefault + 39828
	20  Python                              0x0000000100e053f0 _PyEval_EvalCode + 444
	21  Python                              0x0000000100e5cce4 run_eval_code_obj + 136
	22  Python                              0x0000000100e5cbf8 run_mod + 112
	23  Python                              0x0000000100e5a434 pyrun_file + 168
	24  Python                              0x0000000100e59d58 pyrun_simple_file + 276
	25  Python                              0x0000000100e59c04 PyRun_SimpleFileExFlags + 80
	26  Python                              0x0000000100e79d2c pymain_run_file + 320
	27  Python                              0x0000000100e7947c Py_RunMain + 916
	28  Python                              0x0000000100e7a6c4 pymain_main + 36
	29  Python                              0x0000000100e7a93c Py_BytesMain + 40
	30  dyld                                0x00000001007990fc start + 520
)
.
msg398934 - (view) Author: E. Paine (epaine) * Date: 2021-08-04 18:53
Thanks for reporting issue and for including the backtrace. I presume you used the Universal 2 installer, given that you are running an M1 mac? 

Kevin, do you have access to the macOS 12 beta to help test whether this is a Tkinter or Tk bug? (I assume the latter, as it is likely Apple have changed the API again)
msg398952 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2021-08-04 20:29
Thanks for the report. I verified that the crash also occurs on an Intel Mac VM with Monterey beta 4 using the current python.org universal2 installers for 3.9.6 and 3.10.0rc1; they both have a private copy of Tk 8.6.11; so the problem does not appear to be Apple Silicon (M1) related. For what it's worth, the legacy python.org 3.9.6 Intel-only installer, which uses a copy of Tk 8.6.8, does not crash the Monterey beta 4. And no such failures are observed using any of those installers on the current Big Sur 11.5.1 release.
msg398973 - (view) Author: Nythepegasus (Nythepegasus) Date: 2021-08-05 07:57
I used brew.sh to install Python, which I think uses the universal installer (although I can’t check, reinstalling macOS after hours of failing to downgrade back to Big Sur). I can’t remember the exact error, but it seemed to be from Apple’s end since it complained about not having access to the save/open dialog box. After I reinstall macOS, if you need further testing, i’m open to trying.
On Aug 4, 2021, 2:53 PM -0400, E. Paine <report@bugs.python.org>, wrote:
>
> E. Paine <xepaine13@gmail.com> added the comment:
>
> Thanks for reporting issue and for including the backtrace. I presume you used the Universal 2 installer, given that you are running an M1 mac?
>
> Kevin, do you have access to the macOS 12 beta to help test whether this is a Tkinter or Tk bug? (I assume the latter, as it is likely Apple have changed the API again)
>
> ----------
> components: +macOS
> nosy: +epaine, ned.deily, ronaldoussoren, serhiy.storchaka, wordtech
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue44828>
> _______________________________________
msg399024 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2021-08-05 18:22
> I used brew.sh to install Python, which I think uses the universal installer

As far as I know, Homebrew builds its own Python and Tk.

> After I reinstall macOS, if you need further testing, i’m open to trying.

Thanks. I think the next step would be to try to reproduce just using Tcl and Tk as this most likely is an issue in Tk rather than Python.  It's also quite possible that the underlying problem will be fixed in a future Monterey beta. Alas, I don't have time to look further into this in the immediate future.  Perhaps someone can follow up directly with the Tk folks.
msg399119 - (view) Author: Marc Culler (Marc.Culler) * Date: 2021-08-06 18:26
I built Tcl and Tk 8.6 on Monterey beta (21A5294g) and I see this
traceback in the Wish file dialog demo.  Note that this is *not* an
error.  The file dialog works fine.  This is a non-fatal
NSInternalInconsistencyException which prints a traceback to stderr.
It occurs within a call to [NSSavePanel runModal] which is entirely
Apple code.  The runModal method is not deprecated.  Most likely, when
Apple releases Monterey the assert command will have been removed,
possibly replaced by a call to NSLog which writes information into a
log file rather than print it to stderr.  (NSLog itself prints to
stderr when debugging is enabled.)  Of course macOS apps run without
stderr, so you will only see this traceback when running a python
program from the terminal.  (Any linux user who runs linux apps from
the terminal is used to seeing lots of stderr messages in stderr.  Try
running okular from a terminal sometime.  So we shouldn't complain too
much.)

Anyway, this looks harmless and the messages will almost surely go
away in the production version.  However, there are several new
deprecations related to specifying preferred file types in a file
dialog which I will address in Tk before Monterey is released.

Beta releases are betas, even for macOS.

- Marc

On Thu, Aug 5, 2021 at 1:23 PM Ned Deily <report@bugs.python.org> wrote:
>
>
> Ned Deily <nad@python.org> added the comment:
>
> > I used brew.sh to install Python, which I think uses the universal installer
>
> As far as I know, Homebrew builds its own Python and Tk.
>
> > After I reinstall macOS, if you need further testing, i’m open to trying.
>
> Thanks. I think the next step would be to try to reproduce just using Tcl and Tk as this most likely is an issue in Tk rather than Python.  It's also quite possible that the underlying problem will be fixed in a future Monterey beta. Alas, I don't have time to look further into this in the immediate future.  Perhaps someone can follow up directly with the Tk folks.
>
> ----------
> nosy: +culler
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue44828>
> _______________________________________
msg399122 - (view) Author: Marc Culler (culler) * Date: 2021-08-06 18:32
I should have mentioned that I tested on Intel hardware, not M1.  I do not have access to an M1 Apple at this time.
msg399128 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2021-08-06 18:54
Thanks for looking into this, Marc.
msg400570 - (view) Author: Mark Lierley (mlierley) * Date: 2021-08-30 02:45
I am also experiencing this issue.

I have an M1 Macbook Air running MaOS Monterey Version 12.0 Beta (21A5304g) with a fresh install of Python 3.9.6. 

When attempting to save or open anything from either the editor or console window I get the following error message "The Save file operation failed. The save file operation failed to connect to the open and save panel service.”

I have granted the IDEL full drive access which hasn't resolved the issue. The dialog prevents any savings from occurring making the IDEL useless. 

I have submitted this issue through Apple's Feedback tool as well.
msg401187 - (view) Author: Fahim Faisal (i3p9) Date: 2021-09-06 22:41
Can also confirm this issue, tested on M1 and Intel Mac and both has the same error when using Monterey 12.0 Beta 21A5506j. 

On the same computer, using Big Sur, saves the file successfully and no error present. Seems like a Monterey issue, not dependent on specific hardware. (Intel/M1)

Tested on fresh Python 3.9.6 (tk version 8.6) Installation on Big Sur and Monterey Beta (Build 21A5506j) on a M1 Macbook Pro and Early 2015 13" Macbook Pro.
msg403043 - (view) Author: David Melgar (enki1711) Date: 2021-10-02 02:04
Same issue. Running Monterey beta. Experiencing crash.

Is there any plan for a fix or is the plan to wait for Monterey to release?
msg403600 - (view) Author: Marc Culler (culler) * Date: 2021-10-10 16:06
Unfortunately, I am still seeing this failure in Monterey beta 9.  However, we are no longer alone.  Here is a report of the same issue in Android Studio:

https://stackoverflow.com/questions/69068842/android-studio-open-file-operation-failed-the-open-file-operation-failed-to-co

This is reportedly fixed in the Adroid Studio beta, so maybe someone will be able to figure out what Google did to workaround the problem.
msg403603 - (view) Author: Marc Culler (culler) * Date: 2021-10-10 17:05
I was able to fix this problem for Tk on Monterey beta [21A5543b].
The fix has been committed to the tip of the core-8-6-branch in the
Tk fossil repository.

Here is a synopsis.  Tk used to open the file dialog by calling
[NSApp runModalForWindow:panel].  Starting with the release of 10.14
this call would produce a warning message on stderr saying that
[NSOpenPanel runModal] should be used instead.  But on systems older
than 10.14, the runModal method would fail because the completion handler
would not get called.  Now, with 12.0 (at least in the beta) calling
[NSOpenPanel runModal] produces an error dialog saying "The open file
operation failed to connect to the open and save panel service" and
this would be accompanied by a traceback printed on stderr for an
assertion error.  (It was not a "crash" but the file selection would
fail.)  However, it turns out that calling [NSApp runModalForWindow:panel]
no longer produces the warning in 12.0, and it works correctly.

So my workaround was to add conditional code that only calls the runModal
method on 10.14 and 10.15 and calls runModalForWindow on other versions
of macOS.  I tested on 10.15 and it works there as well.

Needless to say, none of these changes are documented by Apple.
msg403647 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2021-10-11 10:46
Marc, thanks for the update.

Will there be a Tcl/Tk release soonish that includes this fix? 

Alternatively, is there patch that we can apply to the latest release when building the copy of Tk included with the installers?
msg403652 - (view) Author: Marc Culler (culler) * Date: 2021-10-11 12:37
Hi Ronald,
There is no calendar scheduling for Tk releases.  Don Porter decides when they happen.  But I think we are due for another one soonish.  In case it doesn't happen before the next Python release I will attach the patch file for commit a32262e9.  (Note that this is subject to change - I still need to test on 10.14.) I believe that this patch is completely self-contained and can be applied to the 8.6.11 release.

(Hint: Tk uses fossil as its SCM system.  On a fossil timeline, clicking any two nodes generates their diff.  The Tk timeline is at https://core.tcl-lang.org/tk/timeline)
msg403661 - (view) Author: Guy DeStefano (guydestefano) Date: 2021-10-11 17:49
Please help me.  Am new to Python, and don't know enough to post here, but I will try.  Have written a couple of programs that use tkinter, especially tkinter.filedialog.askopenfilenames, and as everyone else mine has quit working since Monterey. I have a macOS Monterey version beta        ( 21A5543b ).  Am using Python3 v3.10.0.  Have tried using v3.11.0a1, but could not even compile, says that import ( PIL ) does not exist.  Put back v 3.10.0 and am back to no filedialog.  Is Apple attempting to do away with the file API.  Just asking. Thank you.
msg403662 - (view) Author: Marc Culler (culler) * Date: 2021-10-11 18:10
No, Apple is not going to do away with their NSOpenPanel.  There is always some churn when they release a new OS.  Subtle changes to APIs can occur with no warning and no documentation.  Sometimes they are bugs. Sometimes they disappear when the OS is released.  Sometimes they are permanent.  I would not recommend using a beta version of the OS to develop your tkinter app.
msg403664 - (view) Author: Guy DeStefano (guydestefano) Date: 2021-10-11 18:14
Thank you very
Guy DeStefano

On Mon, Oct 11, 2021 at 2:10 PM Marc Culler <report@bugs.python.org> wrote:

>
> Marc Culler <marc.culler@gmail.com> added the comment:
>
> No, Apple is not going to do away with their NSOpenPanel.  There is always
> some churn when they release a new OS.  Subtle changes to APIs can occur
> with no warning and no documentation.  Sometimes they are bugs. Sometimes
> they disappear when the OS is released.  Sometimes they are permanent.  I
> would not recommend using a beta version of the OS to develop your tkinter
> app.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue44828>
> _______________________________________
>
msg403665 - (view) Author: Guy DeStefano (guydestefano) Date: 2021-10-11 18:15
Thank you very much for the reply. Sorry for previous text.
Guy DeStefano

On Mon, Oct 11, 2021 at 2:10 PM Marc Culler <report@bugs.python.org> wrote:

>
> Marc Culler <marc.culler@gmail.com> added the comment:
>
> No, Apple is not going to do away with their NSOpenPanel.  There is always
> some churn when they release a new OS.  Subtle changes to APIs can occur
> with no warning and no documentation.  Sometimes they are bugs. Sometimes
> they disappear when the OS is released.  Sometimes they are permanent.  I
> would not recommend using a beta version of the OS to develop your tkinter
> app.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue44828>
> _______________________________________
>
msg403667 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2021-10-11 18:24
@Guy, thanks for your interest but in the future please don't use the issue tracker as a help forum. There are lots of places to ask about such matters; https://www.python.org/about/help/ has a good list of resources and, among the Python-specific mailing lists at https://www.python.org/about/help/, there are ones specifically for Python usage on macOS (https://mail.python.org/mailman/listinfo/pythonmac-sig) and Tkinter usage (https://mail.python.org/mailman/listinfo/tkinter-discuss).
msg403668 - (view) Author: Guy DeStefano (guydestefano) Date: 2021-10-11 18:31
I appreciate the information, In the future I will do as is stated.  Thanks
for the reply.
Guy DeStefano

On Mon, Oct 11, 2021 at 2:24 PM Ned Deily <report@bugs.python.org> wrote:

>
> Ned Deily <nad@python.org> added the comment:
>
> @Guy, thanks for your interest but in the future please don't use the
> issue tracker as a help forum. There are lots of places to ask about such
> matters; https://www.python.org/about/help/ has a good list of resources
> and, among the Python-specific mailing lists at
> https://www.python.org/about/help/, there are ones specifically for
> Python usage on macOS (
> https://mail.python.org/mailman/listinfo/pythonmac-sig) and Tkinter usage
> (https://mail.python.org/mailman/listinfo/tkinter-discuss).
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue44828>
> _______________________________________
>
History
Date User Action Args
2021-10-11 18:31:07guydestefanosetmessages: + msg403668
2021-10-11 18:24:11ned.deilysetmessages: + msg403667
2021-10-11 18:15:48guydestefanosetmessages: + msg403665
2021-10-11 18:14:15guydestefanosetmessages: + msg403664
2021-10-11 18:10:12cullersetmessages: + msg403662
2021-10-11 17:49:47guydestefanosetnosy: + guydestefano

messages: + msg403661
versions: - Python 3.9, Python 3.11
2021-10-11 12:37:05cullersetfiles: + openfile.patch
keywords: + patch
messages: + msg403652
2021-10-11 10:46:26ronaldoussorensetmessages: + msg403647
2021-10-10 17:05:34cullersetmessages: + msg403603
2021-10-10 16:06:35cullersetmessages: + msg403600
2021-10-02 02:04:03enki1711setnosy: + enki1711
messages: + msg403043
2021-09-06 22:41:33i3p9setnosy: + i3p9
messages: + msg401187
2021-08-30 02:45:16mlierleysetfiles: + Screen Shot 2021-08-29 at 7.44.33 PM.png
nosy: + mlierley
messages: + msg400570

2021-08-06 18:54:37ned.deilysetmessages: + msg399128
2021-08-06 18:32:31cullersetmessages: + msg399122
2021-08-06 18:26:13Marc.Cullersetnosy: + Marc.Culler
messages: + msg399119
2021-08-05 18:22:52ned.deilysetnosy: + culler
messages: + msg399024
2021-08-05 07:57:49Nythepegasussetmessages: + msg398973
title: Using tkinter.filedialog crashes on macOS 12 Monterey beta 4 with tk8.6.11 from python.org installers -> Using tkinter.filedialog crashes on macOS Python 3.9.6
2021-08-04 20:29:16ned.deilysettitle: Using tkinter.filedialog crashes on macOS Python 3.9.6 -> Using tkinter.filedialog crashes on macOS 12 Monterey beta 4 with tk8.6.11 from python.org installers
messages: + msg398952
versions: + Python 3.10, Python 3.11
2021-08-04 18:53:11epainesetnosy: + ronaldoussoren, wordtech, ned.deily, serhiy.storchaka, epaine
messages: + msg398934
components: + macOS
2021-08-04 11:21:33Nythepegasuscreate