[Python-Dev] 2.3.1

Kurt B. Kaiser kbk@shore.net
Sun, 27 Jul 2003 00:20:03 -0400


"Tim Peters" <tim.one@comcast.net> writes:

> Sorry, that one isn't a possibility.  After 3 years and 50 comments and at
> least a dozen attempts by Tk wizards to fix it, I finally gave up on this
> bug report, and closed it as hopeless:
>
>     Programs using Tkinter sometimes can't shut down (Windows)
>     http://www.python.org/sf/216289
>
> The only known workaround is never opening Tcl/Tk clients with python.exe.

OK, I've submitted patch 778323, copied below, which opens a Tk message box.

This is a relatively low risk patch:

1. One line added to PyShell to set a timeout on the socket.accept().  In
   the case Alex raises, it's likely the user process will block waiting 
   for the subprocess to connect, leaving a stuck process for the user to
   clean up.  The timeout fixes that.

2. One line added to run.py which calls the Tk error message method.
   This line and the method only execute when a socket error is raised and
   the situation is already pretty bleak.

Tested on XP and RH6.2.

The text printed to sys.__stderr__ would get removed at 2.3.1.

-- 
KBK

Index: PyShell.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/idlelib/PyShell.py,v
retrieving revision 1.81
diff -c -p -r1.81 PyShell.py
*** PyShell.py	27 Jul 2003 03:24:18 -0000	1.81
--- PyShell.py	27 Jul 2003 03:41:14 -0000
*************** class ModifiedInterpreter(InteractiveInt
*** 349,354 ****
--- 349,356 ----
              sys.exit()
          self.spawn_subprocess()
          # Accept the connection from the Python execution server
+         ## XXX 26Jul03 KBK Should raise a Tk exception message on timeout
+         self.rpcclt.listening_sock.settimeout(20)
          self.rpcclt.accept()
          self.rpcclt.register("stdin", self.tkconsole)
          self.rpcclt.register("stdout", self.tkconsole.stdout)
Index: run.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/idlelib/run.py,v
retrieving revision 1.25
diff -c -p -r1.25 run.py
*** run.py	22 Jun 2003 07:52:56 -0000	1.25
--- run.py	27 Jul 2003 03:41:30 -0000
*************** def manage_socket(address):
*** 103,112 ****
--- 103,122 ----
                                                + err[1] + ", retrying...."
      else:
          print>>sys.__stderr__, "\nConnection to Idle failed, exiting."
+         show_socket_error(err)
          global exit_now
          exit_now = True
          return
      server.handle_request() # A single request only
+ 
+ def show_socket_error(err):
+     import Tkinter
+     import tkMessageBox
+     root = Tkinter.Tk()
+     root.withdraw()
+     msg = "Can't Connect to IDLE User Process: %s"
+     tkMessageBox.showerror("IDLE Subprocess Error", msg % err[1], parent=root)
+     root.destroy()
  
  def print_exception():
      flush_stdout()
Index: NEWS.txt
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/idlelib/NEWS.txt,v
retrieving revision 1.23
diff -c -p -r1.23 NEWS.txt
*** NEWS.txt	27 Jul 2003 03:24:18 -0000	1.23
--- NEWS.txt	27 Jul 2003 04:02:46 -0000
*************** What's New in IDLE 1.0?
*** 3,8 ****
--- 3,11 ----
  
  *Release date: 29-Jul-2003*
  
+ - Added a Tk error dialog to inform the user if the subprocess can't connect
+   to the user GUI process.  Added a timeout to the latter's listening socket.
+ 
  - Added a banner to the shell discussimg warnings possibly raised by personal
    firewall software.  Added same comment to README.txt.