Skip to content

Commit 5ee0567

Browse files
Fixes python#11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Without this patch IDLE will crash reliably on OSX when Tkinter is linked to TkCocoa 8.5.x. To reproduce: * Create a new file (script.py) with the following two lines: x = input('prompt: ') print(x) * Save the script * Run the script using the F5 keyboard shortcut (running from the menu works fine) The patch is a fairly crude hack, but we haven't found a better workaround for this Tk bug yet.
1 parent 6edd8c1 commit 5ee0567

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎Lib/idlelib/ScriptBinding.py‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from idlelib import PyShell, IOBinding
2828

2929
from idlelib.configHandler import idleConf
30+
from idlelib import macosxSupport
3031

3132
indent_message = """Error: Inconsistent indentation detected!
3233
@@ -52,6 +53,9 @@ def __init__(self, editwin):
5253
self.flist = self.editwin.flist
5354
self.root = self.editwin.root
5455

56+
if macosxSupport.runningAsOSXApp():
57+
self.editwin.text_frame.bind('<<run-module-event-2>>', self._run_module_event)
58+
5559
def check_module_event(self, event):
5660
filename = self.getfilename()
5761
if not filename:
@@ -116,14 +120,27 @@ def checksyntax(self, filename):
116120
shell.set_warning_stream(saved_stream)
117121

118122
def run_module_event(self, event):
123+
if macosxSupport.runningAsOSXApp():
124+
# Tk-Cocoa in MacOSX is broken until at least
125+
# Tk 8.5.9, and without this rather
126+
# crude workaround IDLE would hang when a user
127+
# tries to run a module using the keyboard shortcut
128+
# (the menu item works fine).
129+
self.editwin.text_frame.after(200,
130+
lambda: self.editwin.text_frame.event_generate('<<run-module-event-2>>'))
131+
return 'break'
132+
else:
133+
return self._run_module_event(event)
134+
135+
def _run_module_event(self, event):
119136
"""Run the module after setting up the environment.
120137
121138
First check the syntax. If OK, make sure the shell is active and
122139
then transfer the arguments, set the run environment's working
123140
directory to the directory of the module being executed and also
124141
add that directory to its sys.path if not already included.
125-
126142
"""
143+
127144
filename = self.getfilename()
128145
if not filename:
129146
return 'break'

‎Misc/NEWS‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Core and Builtins
2323
Library
2424
-------
2525

26+
- Issue #11088: don't crash when using F5 to run a script in IDLE on MacOSX
27+
with Tk 8.5.
28+
2629
- Issue #9516: Issue #9516: avoid errors in sysconfig when MACOSX_DEPLOYMENT_TARGET
2730
is set in shell.
2831

0 commit comments

Comments
 (0)