From fb5e5b436d2a0972eb09af031eedbbd485e909bd 2005-09-20 20:13:04 From: fperez Date: 2005-09-20 20:13:04 Subject: [PATCH] Minor fixes in genutils, and a BIG fix for threading. I _think_ I got Ctrl-C to work in the threaded shells, and the solution is in fact absolutely trivial. The new code is _much_ simpler than what we had! This needs testing, because I find it almost hard to believe that we hadn't tried this before. But if it works, great! The only limitation is that in threaded mode, the traceback shows the internal sigint handler frame. Big deal, it's just cosmetic. --- diff --git a/IPython/Shell.py b/IPython/Shell.py index e24bd65..9b59088 100644 --- a/IPython/Shell.py +++ b/IPython/Shell.py @@ -4,7 +4,7 @@ All the matplotlib support code was co-developed with John Hunter, matplotlib's author. -$Id: Shell.py 802 2005-09-06 03:49:12Z fperez $""" +$Id: Shell.py 874 2005-09-20 20:13:04Z fperez $""" #***************************************************************************** # Copyright (C) 2001-2004 Fernando Perez @@ -34,9 +34,6 @@ from IPython.Struct import Struct from IPython.Magic import Magic from IPython import ultraTB -# global flag to pass around information about Ctrl-C without exceptions -KBINT = False - # global flag to turn on/off Tk support. USE_TK = False @@ -244,18 +241,8 @@ class IPShellEmbed: #----------------------------------------------------------------------------- def sigint_handler (signum,stack_frame): """Sigint handler for threaded apps. - - This is a horrible hack to pass information about SIGINT _without_ using - exceptions, since I haven't been able to properly manage cross-thread - exceptions in GTK/WX. In fact, I don't think it can be done (or at least - that's my understanding from a c.l.py thread where this was discussed).""" - - global KBINT - - print '\nKeyboardInterrupt - Press to continue.', - Term.cout.flush() - # Set global flag so that runsource can know that Ctrl-C was hit - KBINT = True + """ + raise KeyboardInterrupt class MTInteractiveShell(InteractiveShell): """Simple multi-threaded shell.""" @@ -290,13 +277,6 @@ class MTInteractiveShell(InteractiveShell): Modified version of code.py's runsource(), to handle threading issues. See the original for full docstring details.""" - - global KBINT - - # If Ctrl-C was typed, we reset the flag and return right away - if KBINT: - KBINT = False - return False try: code = self.compile(source, filename, symbol) diff --git a/IPython/genutils.py b/IPython/genutils.py index efde7c3..a66ed39 100644 --- a/IPython/genutils.py +++ b/IPython/genutils.py @@ -5,7 +5,7 @@ General purpose utilities. This is a grab-bag of stuff I find useful in most programs I write. Some of these things are also convenient when working at the command line. -$Id: genutils.py 703 2005-08-16 17:34:44Z fperez $""" +$Id: genutils.py 874 2005-09-20 20:13:04Z fperez $""" #***************************************************************************** # Copyright (C) 2001-2004 Fernando Perez. @@ -732,7 +732,16 @@ def get_home_dir(): "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders") homedir = wreg.QueryValueEx(key,'Personal')[0] key.Close() + if not isdir(homedir): + e = ('Invalid "Personal" folder registry key ' + 'typically "My Documents".\n' + 'Value: %s\n' + 'This is not a valid directory on your system.' % + homedir) + raise HomeDirError(e) return homedir + except HomeDirError: + raise except: return 'C:\\' elif os.name == 'dos': diff --git a/IPython/iplib.py b/IPython/iplib.py index 858be96..d378340 100644 --- a/IPython/iplib.py +++ b/IPython/iplib.py @@ -6,7 +6,7 @@ Requires Python 2.1 or newer. This file contains all the classes and helper functions specific to IPython. -$Id: iplib.py 807 2005-09-07 01:55:33Z fperez $ +$Id: iplib.py 874 2005-09-20 20:13:04Z fperez $ """ #***************************************************************************** @@ -959,7 +959,7 @@ class InteractiveShell(code.InteractiveConsole, Logger, Magic): In particular, make sure no Python keywords/builtins are in it.""" no_alias = self.no_alias - for k in self.alias_table: + for k in self.alias_table.keys(): if k in no_alias: del self.alias_table[k] if verbose: diff --git a/doc/ChangeLog b/doc/ChangeLog index 32203ef..21d9ee8 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,16 @@ +2005-09-20 Fernando Perez + + * IPython/Shell.py (sigint_handler): Drastic simplification which + also seems to make Ctrl-C work correctly across threads! This is + so simple, that I can't beleive I'd missed it before. Needs more + testing, though. + + * IPython/genutils.py (get_home_dir): add protection against + non-dirs in win32 registry. + + * IPython/iplib.py (InteractiveShell.alias_table_validate): fix + bug where dict was mutated while iterating (pysh crash). + 2005-09-06 Fernando Perez * IPython/iplib.py (handle_auto): Fix inconsistency arising from