From noreply at sourceforge.net Thu Jan 1 18:58:06 2004 From: noreply at sourceforge.net (SourceForge.net) Date: Thu Jan 1 18:58:10 2004 Subject: [Idle-dev] [ idlefork-Patches-869012 ] Update linecache when showing exceptions Message-ID: Patches item #869012, was opened at 2004-01-02 01:58 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=309579&aid=869012&group_id=9579 Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Noam Raphael (noamr) Assigned to: Nobody/Anonymous (nobody) Summary: Update linecache when showing exceptions Initial Comment: When exceptions are shown, the linecache module is being used. If a file was changed while IDLE was running, linecache won't know about it and will show the line from the file in cache, which is very confusing sometimes, since it may have no relation to what actually caused the exception. An example: >>> file("t.py", "w").write("1/0") >>> execfile("t.py") Traceback (most recent call last): File "", line 1, in -toplevel- execfile("t.py") File "t.py", line 1, in -toplevel- 1/0 ZeroDivisionError: integer division or modulo by zero >>> file("t.py", "w").write("2/0") >>> execfile("t.py") Traceback (most recent call last): File "", line 1, in -toplevel- execfile("t.py") File "t.py", line 1, in -toplevel- 1/0 <======== Should have been 2/0! ZeroDivisionError: integer division or modulo by zero The solution is to add those two line at the beginning of function print_exception in run.py (after line 113): def print_exception(): + import linecache + linecache.checkcache() This causes the cache to update itself, and the correct line is shown. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=309579&aid=869012&group_id=9579 From kbk at users.sourceforge.net Thu Jan 1 21:35:38 2004 From: kbk at users.sourceforge.net (Kurt B. Kaiser) Date: Thu Jan 1 21:35:41 2004 Subject: [Idle-dev] CVS: idle NEWS.txt,1.26,1.27 run.py,1.24,1.25 Message-ID: Update of /cvsroot/idlefork/idle In directory sc8-pr-cvs1:/tmp/cvs-serv4566 Modified Files: NEWS.txt run.py Log Message: Print correct exception even if source file changed since shell was restarted. IDLEfork Patch 869012 Noam Raphael Modified Files: NEWS.txt run.py Index: NEWS.txt =================================================================== RCS file: /cvsroot/idlefork/idle/NEWS.txt,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -r1.26 -r1.27 *** NEWS.txt 25 Nov 2003 04:52:12 -0000 1.26 --- NEWS.txt 2 Jan 2004 02:35:36 -0000 1.27 *************** *** 8,11 **** --- 8,14 ---- *Release date: XX-XXX-2003* + - Print correct exception even if source file changed since shell was + restarted. IDLEfork Patch 869012 Noam Raphael + - Port Martin v. Loewis corrections to IOBinding.py (1.20, 1.21) from Python IDLE. Closes IDLEfork Bug 778547, Python Bugs 788378, 774680, 805728 Index: run.py =================================================================== RCS file: /cvsroot/idlefork/idle/run.py,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -r1.24 -r1.25 *** run.py 24 Nov 2003 03:08:08 -0000 1.24 --- run.py 2 Jan 2004 02:35:36 -0000 1.25 *************** *** 112,115 **** --- 112,117 ---- def print_exception(): + import linecache + linecache.checkcache() flush_stdout() efile = sys.stderr From noreply at sourceforge.net Thu Jan 1 23:00:40 2004 From: noreply at sourceforge.net (SourceForge.net) Date: Thu Jan 1 23:00:45 2004 Subject: [Idle-dev] [ idlefork-Patches-869012 ] Update linecache when showing exceptions Message-ID: Patches item #869012, was opened at 2004-01-01 18:58 Message generated for change (Comment added) made by kbk You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=309579&aid=869012&group_id=9579 Category: None Group: None >Status: Closed >Resolution: Accepted Priority: 5 Submitted By: Noam Raphael (noamr) >Assigned to: Kurt B. Kaiser (kbk) Summary: Update linecache when showing exceptions Initial Comment: When exceptions are shown, the linecache module is being used. If a file was changed while IDLE was running, linecache won't know about it and will show the line from the file in cache, which is very confusing sometimes, since it may have no relation to what actually caused the exception. An example: >>> file("t.py", "w").write("1/0") >>> execfile("t.py") Traceback (most recent call last): File "", line 1, in -toplevel- execfile("t.py") File "t.py", line 1, in -toplevel- 1/0 ZeroDivisionError: integer division or modulo by zero >>> file("t.py", "w").write("2/0") >>> execfile("t.py") Traceback (most recent call last): File "", line 1, in -toplevel- execfile("t.py") File "t.py", line 1, in -toplevel- 1/0 <======== Should have been 2/0! ZeroDivisionError: integer division or modulo by zero The solution is to add those two line at the beginning of function print_exception in run.py (after line 113): def print_exception(): + import linecache + linecache.checkcache() This causes the cache to update itself, and the correct line is shown. ---------------------------------------------------------------------- >Comment By: Kurt B. Kaiser (kbk) Date: 2004-01-01 23:00 Message: Logged In: YES user_id=149084 Thanks for the patch! IDLEfork run.py 1.25 IDLE (python 2.4a0) run.py 1.27 ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=309579&aid=869012&group_id=9579 From kbk at users.sourceforge.net Sun Jan 4 23:50:21 2004 From: kbk at users.sourceforge.net (Kurt B. Kaiser) Date: Sun Jan 4 23:50:25 2004 Subject: [Idle-dev] CVS: idle setup.py,1.15,1.16 Message-ID: Update of /cvsroot/idlefork/idle In directory sc8-pr-cvs1:/tmp/cvs-serv29595 Modified Files: setup.py Log Message: Now able to build the extension when Python is not installed. M setup.py Index: setup.py =================================================================== RCS file: /cvsroot/idlefork/idle/setup.py,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -r1.15 -r1.16 *** setup.py 30 May 2003 02:42:02 -0000 1.15 --- setup.py 5 Jan 2004 04:50:19 -0000 1.16 *************** *** 7,10 **** --- 7,12 ---- idle_name = "idle" + incl_dirs = ['../../Include', '../..'] + # Name of 'package' to be installed in site-packages: pkgname = idle_name + "lib" *************** *** 114,118 **** package_dir = {pkgname: pkg_dir}, packages = [pkgname], ! ext_modules = [Extension("interrupt", ["interruptmodule.c"])], scripts = [os.path.join(pkg_dir, idle_name)] ) --- 116,120 ---- package_dir = {pkgname: pkg_dir}, packages = [pkgname], ! ext_modules = [Extension("interrupt", ["interruptmodule.c"], incl_dirs)], scripts = [os.path.join(pkg_dir, idle_name)] ) From kbk at users.sourceforge.net Sun Jan 4 23:58:53 2004 From: kbk at users.sourceforge.net (Kurt B. Kaiser) Date: Sun Jan 4 23:58:57 2004 Subject: [Idle-dev] CVS: idle NEWS.txt, 1.27, 1.28 PyShell.py, 1.79, 1.80 ScriptBinding.py, 1.25, 1.26 run.py, 1.25, 1.26 Message-ID: Update of /cvsroot/idlefork/idle In directory sc8-pr-cvs1:/tmp/cvs-serv30424 Modified Files: NEWS.txt PyShell.py ScriptBinding.py run.py Log Message: Added a Tk error dialog to run.py inform the user if the subprocess can't connect to the user GUI process. Added Tk error dialogs to PyShell.py to announce a failure to bind the port or connect to the subprocess. Clean up error handling during connection initiation phase. This is an update of Python Patch 778323, without the listening socket timeout in Python 2.4 IDLE (since Python 2.2.1 doesn't support that.) M NEWS.txt M PyShell.py M ScriptBinding.py M run.py Index: NEWS.txt =================================================================== RCS file: /cvsroot/idlefork/idle/NEWS.txt,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -r1.27 -r1.28 *** NEWS.txt 2 Jan 2004 02:35:36 -0000 1.27 --- NEWS.txt 5 Jan 2004 04:58:51 -0000 1.28 *************** *** 6,10 **** =================================== ! *Release date: XX-XXX-2003* - Print correct exception even if source file changed since shell was --- 6,17 ---- =================================== ! *Release date: XX-XXX-2004* ! ! - Added a Tk error dialog to run.py inform the user if the subprocess can't ! connect to the user GUI process. Added Tk error dialogs to PyShell.py to ! announce a failure to bind the port or connect to the subprocess. Clean up ! error handling during connection initiation phase. This is an update of ! Python Patch 778323, without the listening socket timeout in Python 2.4 IDLE ! (since Python 2.2.1 doesn't support that.) - Print correct exception even if source file changed since shell was Index: PyShell.py =================================================================== RCS file: /cvsroot/idlefork/idle/PyShell.py,v retrieving revision 1.79 retrieving revision 1.80 diff -C2 -r1.79 -r1.80 *** PyShell.py 25 Nov 2003 03:42:32 -0000 1.79 --- PyShell.py 5 Jan 2004 04:58:51 -0000 1.80 *************** *** 255,259 **** else: self.pyshell = PyShell(self) ! self.pyshell.begin() return self.pyshell --- 255,261 ---- else: self.pyshell = PyShell(self) ! if self.pyshell: ! if not self.pyshell.begin(): ! return None return self.pyshell *************** *** 348,351 **** --- 350,356 ---- def start_subprocess(self): + # spawning first avoids passing a listening socket to the subprocess + self.spawn_subprocess() + #time.sleep(20) # test to simulate GUI not accepting connection addr = (LOCALHOST, self.port) # Idle starts listening for connection on localhost *************** *** 356,367 **** break except socket.error, err: ! print>>sys.__stderr__,"IDLE socket error: " + err[1]\ ! + ", retrying..." else: ! display_port_binding_error() ! sys.exit() ! self.spawn_subprocess() # Accept the connection from the Python execution server ! self.rpcclt.accept() self.rpcclt.register("stdin", self.tkconsole) self.rpcclt.register("stdout", self.tkconsole.stdout) --- 361,375 ---- break except socket.error, err: ! pass else: ! self.display_port_binding_error() ! return None # Accept the connection from the Python execution server ! #self.rpcclt.listening_sock.settimeout(10) # no settimeout() in Python 2.2.1 ! try: ! self.rpcclt.accept() ! except: # socket.timeout, err: # no settimeout() in Python 2.2.1 ! self.display_no_subprocess_error() ! return None self.rpcclt.register("stdin", self.tkconsole) self.rpcclt.register("stdout", self.tkconsole.stdout) *************** *** 372,379 **** self.transfer_path() self.poll_subprocess() def restart_subprocess(self): if self.restarting: ! return self.restarting = True # close only the subprocess debugger --- 380,388 ---- self.transfer_path() self.poll_subprocess() + return self.rpcclt def restart_subprocess(self): if self.restarting: ! return self.rpcclt self.restarting = True # close only the subprocess debugger *************** *** 392,396 **** console.executing = False self.spawn_subprocess() ! self.rpcclt.accept() self.transfer_path() # annotate restart in shell window and mark it --- 401,409 ---- console.executing = False self.spawn_subprocess() ! try: ! self.rpcclt.accept() ! except socket.timeout, err: ! self.display_no_subprocess_error() ! return None self.transfer_path() # annotate restart in shell window and mark it *************** *** 411,414 **** --- 424,428 ---- debug.load_breakpoints() self.restarting = False + return self.rpcclt def __request_interrupt(self): *************** *** 419,423 **** def kill_subprocess(self): ! self.rpcclt.close() self.unix_terminate() self.tkconsole.executing = False --- 433,440 ---- def kill_subprocess(self): ! try: ! self.rpcclt.close() ! except AttributeError: # no socket ! pass self.unix_terminate() self.tkconsole.executing = False *************** *** 642,652 **** del c[key] - def display_executing_dialog(self): - tkMessageBox.showerror( - "Already executing", - "The Python Shell window is already executing a command; " - "please wait until it is finished.", - master=self.tkconsole.text) - def runcommand(self, code): "Run the code without invoking the debugger" --- 659,662 ---- *************** *** 699,702 **** --- 709,740 ---- self.tkconsole.stderr.write(s) + def display_port_binding_error(self): + tkMessageBox.showerror( + "Port Binding Error", + "IDLE can't bind TCP/IP port 8833, which is necessary to " + "communicate with its Python execution server. Either " + "no networking is installed on this computer or another " + "process (another IDLE?) is using the port. Run IDLE with the -n " + "command line switch to start without a subprocess and refer to " + "Help/IDLE Help 'Running without a subprocess' for further " + "details.", + master=self.tkconsole.text) + + def display_no_subprocess_error(self): + tkMessageBox.showerror( + "Subprocess Startup Error", + "IDLE's subprocess didn't make connection. Either IDLE can't " + "start a subprocess or personal firewall software is blocking " + "the connection.", + master=self.tkconsole.text) + + def display_executing_dialog(self): + tkMessageBox.showerror( + "Already executing", + "The Python Shell window is already executing a command; " + "please wait until it is finished.", + master=self.tkconsole.text) + + class PyShell(OutputWindow): *************** *** 769,774 **** # self.pollinterval = 50 # millisec - if use_subprocess: - self.interp.start_subprocess() reading = False --- 807,810 ---- *************** *** 882,885 **** --- 918,925 ---- if use_subprocess: nosub = '' + client = self.interp.start_subprocess() + if not client: + self.close() + return None else: nosub = "==== No Subprocess ====" *************** *** 889,897 **** self.showprompt() import Tkinter ! Tkinter._default_root = None ! ! def interact(self): ! self.begin() ! self.top.mainloop() def readline(self): --- 929,934 ---- self.showprompt() import Tkinter ! Tkinter._default_root = None # 03Jan04 KBK What's this? ! return client def readline(self): *************** *** 1276,1284 **** if not args: flist.new() ! if enable_shell: ! flist.open_shell() ! elif enable_shell: ! flist.pyshell = PyShell(flist) ! flist.pyshell.begin() shell = flist.pyshell # handle remaining options: --- 1313,1319 ---- if not args: flist.new() ! if enable_shell: ! if not flist.open_shell(): ! return # couldn't open shell shell = flist.pyshell # handle remaining options: *************** *** 1290,1294 **** if filename and os.path.isfile(filename): shell.interp.execfile(filename) ! if cmd or script: shell.interp.runcommand("""if 1: import sys as _sys --- 1325,1329 ---- if filename and os.path.isfile(filename): shell.interp.execfile(filename) ! if shell and cmd or script: shell.interp.runcommand("""if 1: import sys as _sys *************** *** 1303,1324 **** root.mainloop() root.destroy() - - - def display_port_binding_error(): - print """\ - \nIDLE cannot run. - - IDLE needs to use a specific TCP/IP port (8833) in order to communicate with - its Python execution server. IDLE is unable to bind to this port, and so - cannot start. Here are some possible causes of this problem: - - 1. TCP/IP networking is not installed or not working on this computer - 2. Another program (another IDLE?) is running that uses this port - 3. Personal firewall software is preventing IDLE from using this port - - Run IDLE with the -n command line switch to start without a subprocess - and refer to Help/IDLE Help "Running without a subprocess" for further - details. - """ if __name__ == "__main__": --- 1338,1341 ---- Index: ScriptBinding.py =================================================================== RCS file: /cvsroot/idlefork/idle/ScriptBinding.py,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -r1.25 -r1.26 *** ScriptBinding.py 5 Jun 2003 02:38:32 -0000 1.25 --- ScriptBinding.py 5 Jan 2004 04:58:51 -0000 1.26 *************** *** 138,141 **** --- 138,143 ---- flist = self.editwin.flist shell = flist.open_shell() + if not shell: + return # couldn't open the shell interp = shell.interp if PyShell.use_subprocess: Index: run.py =================================================================== RCS file: /cvsroot/idlefork/idle/run.py,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -r1.25 -r1.26 *** run.py 2 Jan 2004 02:35:36 -0000 1.25 --- run.py 5 Jan 2004 04:58:51 -0000 1.26 *************** *** 50,53 **** --- 50,54 ---- no_exitfunc = del_exitfunc port = 8833 + #time.sleep(15) # test subprocess not responding if sys.argv[1:]: port = int(sys.argv[1]) *************** *** 93,97 **** def manage_socket(address): ! for i in range(6): time.sleep(i) try: --- 94,98 ---- def manage_socket(address): ! for i in range(3): time.sleep(i) try: *************** *** 99,109 **** break except socket.error, err: ! if i < 3: ! print>>sys.__stderr__, ".. ", ! else: ! print>>sys.__stderr__,"\nPython subprocess socket error: "\ ! + err[1] + ", retrying...." else: ! print>>sys.__stderr__, "\nConnection to Idle failed, exiting." global exit_now exit_now = True --- 100,109 ---- break except socket.error, err: ! print>>sys.__stderr__,"IDLE Subprocess: socket error: "\ ! + err[1] + ", retrying...." else: ! print>>sys.__stderr__, "IDLE Subprocess: Connection to "\ ! "IDLE GUI failed, exiting." ! show_socket_error(err, address) global exit_now exit_now = True *************** *** 111,114 **** --- 111,129 ---- server.handle_request() # A single request only + def show_socket_error(err, address): + import Tkinter + import tkMessageBox + root = Tkinter.Tk() + root.withdraw() + if err[0] == 61: # connection refused + msg = "IDLE's subprocess can't connect to %s:%d. This may be due "\ + "to your personal firewall configuration. It is safe to "\ + "allow this internal connection because no data is visible on "\ + "external ports." % address + tkMessageBox.showerror("IDLE Subprocess Error", msg, parent=root) + else: + tkMessageBox.showerror("IDLE Subprocess Error", "Socket Error: %s" % err[1]) + root.destroy() + def print_exception(): import linecache *************** *** 119,123 **** sys.last_type, sys.last_value, sys.last_traceback = excinfo tbe = traceback.extract_tb(tb) ! print >>efile, '\nTraceback (most recent call last):' exclude = ("run.py", "rpc.py", "threading.py", "Queue.py", "RemoteDebugger.py", "bdb.py") --- 134,138 ---- sys.last_type, sys.last_value, sys.last_traceback = excinfo tbe = traceback.extract_tb(tb) ! print>>efile, '\nTraceback (most recent call last):' exclude = ("run.py", "rpc.py", "threading.py", "Queue.py", "RemoteDebugger.py", "bdb.py") From kbk at users.sourceforge.net Wed Jan 21 14:45:21 2004 From: kbk at users.sourceforge.net (Kurt B. Kaiser) Date: Wed Jan 21 14:45:26 2004 Subject: [Idle-dev] CVS: idle NEWS.txt,1.28,1.29 rpc.py,1.26,1.27 Message-ID: Update of /cvsroot/idlefork/idle In directory sc8-pr-cvs1:/tmp/cvs-serv28446 Modified Files: NEWS.txt rpc.py Log Message: rpc.py:SocketIO - Large modules were generating large pickles when downloaded to the execution server. The return of the OK response from the subprocess initialization was interfering and causing the sending socket to be not ready. Add an IO ready test to fix this. Moved the polling IO ready test into pollpacket(). Fix typo in rpc.py, s/b "pickle.PicklingError" not "pickle.UnpicklingError". M rpc.py NEWS.txt Index: NEWS.txt =================================================================== RCS file: /cvsroot/idlefork/idle/NEWS.txt,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -r1.28 -r1.29 *** NEWS.txt 5 Jan 2004 04:58:51 -0000 1.28 --- NEWS.txt 21 Jan 2004 19:45:19 -0000 1.29 *************** *** 8,11 **** --- 8,19 ---- *Release date: XX-XXX-2004* + - run.py:SocketIO - Large modules were generating large pickles when downloaded + to the execution server. The return of the OK response from the subprocess + initialization was interfering and causing the sending socket to be not + ready. Add an IO ready test to fix this. Moved the polling IO ready test + into pollpacket(). + + - Fix typo in rpc.py, s/b "pickle.PicklingError" not "pickle.UnpicklingError". + - Added a Tk error dialog to run.py inform the user if the subprocess can't connect to the user GUI process. Added Tk error dialogs to PyShell.py to Index: rpc.py =================================================================== RCS file: /cvsroot/idlefork/idle/rpc.py,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -r1.26 -r1.27 *** rpc.py 5 Jun 2003 23:51:28 -0000 1.26 --- rpc.py 21 Jan 2004 19:45:19 -0000 1.27 *************** *** 321,325 **** try: s = pickle.dumps(message) ! except pickle.UnpicklingError: print >>sys.__stderr__, "Cannot pickle:", `message` raise --- 321,325 ---- try: s = pickle.dumps(message) ! except pickle.PicklingError: print >>sys.__stderr__, "Cannot pickle:", `message` raise *************** *** 327,331 **** while len(s) > 0: try: ! n = self.sock.send(s) except (AttributeError, socket.error): # socket was closed --- 327,332 ---- while len(s) > 0: try: ! r, w, x = select.select([], [self.sock], []) ! n = self.sock.send(s[:BUFSIZE]) except (AttributeError, socket.error): # socket was closed *************** *** 334,341 **** s = s[n:] - def ioready(self, wait): - r, w, x = select.select([self.sock.fileno()], [], [], wait) - return len(r) - buffer = "" bufneed = 4 --- 335,338 ---- *************** *** 345,349 **** self._stage0() if len(self.buffer) < self.bufneed: ! if not self.ioready(wait): return None try: --- 342,347 ---- self._stage0() if len(self.buffer) < self.bufneed: ! r, w, x = select.select([self.sock.fileno()], [], [], wait) ! if len(r) == 0: return None try: *************** *** 378,382 **** try: message = pickle.loads(packet) ! except: print >>sys.__stderr__, "-----------------------" print >>sys.__stderr__, "cannot unpickle packet:", `packet` --- 376,380 ---- try: message = pickle.loads(packet) ! except pickle.UnpicklingError: print >>sys.__stderr__, "-----------------------" print >>sys.__stderr__, "cannot unpickle packet:", `packet` From kbk at users.sourceforge.net Wed Jan 21 16:44:20 2004 From: kbk at users.sourceforge.net (Kurt B. Kaiser) Date: Wed Jan 21 16:44:24 2004 Subject: [Idle-dev] CVS: idle PyShell.py,1.80,1.81 Message-ID: Update of /cvsroot/idlefork/idle In directory sc8-pr-cvs1:/tmp/cvs-serv22532 Modified Files: PyShell.py Log Message: An error in Rev 1.80 was causing starting w/o subprocess to fail. M PyShell.py Index: PyShell.py =================================================================== RCS file: /cvsroot/idlefork/idle/PyShell.py,v retrieving revision 1.80 retrieving revision 1.81 diff -C2 -r1.80 -r1.81 *** PyShell.py 5 Jan 2004 04:58:51 -0000 1.80 --- PyShell.py 21 Jan 2004 21:44:18 -0000 1.81 *************** *** 921,925 **** if not client: self.close() ! return None else: nosub = "==== No Subprocess ====" --- 921,925 ---- if not client: self.close() ! return False else: nosub = "==== No Subprocess ====" *************** *** 930,934 **** import Tkinter Tkinter._default_root = None # 03Jan04 KBK What's this? ! return client def readline(self): --- 930,934 ---- import Tkinter Tkinter._default_root = None # 03Jan04 KBK What's this? ! return True def readline(self):