diff --git a/IPython/Extensions/ipipe.py b/IPython/Extensions/ipipe.py index e76e0c3..7f9029a 100644 --- a/IPython/Extensions/ipipe.py +++ b/IPython/Extensions/ipipe.py @@ -114,6 +114,11 @@ except NameError: items.reverse() return items +try: # Python 2.4 compatibility + GeneratorExit +except NameError: + GeneratorExit = SystemExit + try: import pwd except ImportError: @@ -666,7 +671,7 @@ def xrepr(item, mode="default"): try: for x in func(mode): yield x - except (KeyboardInterrupt, SystemExit): + except (KeyboardInterrupt, SystemExit, GeneratorExit): raise except Exception: yield (astyle.style_default, repr(item)) @@ -840,20 +845,20 @@ def upgradexattr(attr): """ Convert an attribute descriptor string to a real descriptor object. - If attr already is a descriptor object return if unmodified. A + If attr already is a descriptor object return it unmodified. A ``SelfDescriptor`` will be returned if ``attr`` is ``None``. ``"foo"`` returns an ``AttributeDescriptor`` for the attribute named ``"foo"``. ``"foo()"`` returns a ``MethodDescriptor`` for the method named ``"foo"``. ``"-foo"`` will return an ``IterAttributeDescriptor`` for the attribute named ``"foo"`` and ``"-foo()"`` will return an ``IterMethodDescriptor`` - for the method named ``"foo"``. Furthermore integer will return the appropriate + for the method named ``"foo"``. Furthermore integers will return the appropriate ``IndexDescriptor`` and callables will return a ``FunctionDescriptor``. """ if attr is None: return selfdescriptor elif isinstance(attr, Descriptor): return attr - elif isinstance(attr, str): + elif isinstance(attr, basestring): if attr.endswith("()"): if attr.startswith("-"): return IterMethodDescriptor(attr[1:-2]) diff --git a/IPython/Magic.py b/IPython/Magic.py index 32bdb6d..a6194ca 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -1675,7 +1675,7 @@ Currently the magic system has the following functions:\n""" exit_ignore=exit_ignore) t1 = clock2() t_usr = t1[0]-t0[0] - t_sys = t1[1]-t1[1] + t_sys = t1[1]-t0[1] print "\nIPython CPU timings (estimated):" print " User : %10s s." % t_usr print " System: %10s s." % t_sys @@ -1687,7 +1687,7 @@ Currently the magic system has the following functions:\n""" exit_ignore=exit_ignore) t1 = clock2() t_usr = t1[0]-t0[0] - t_sys = t1[1]-t1[1] + t_sys = t1[1]-t0[1] print "\nIPython CPU timings (estimated):" print "Total runs performed:",nruns print " Times : %10s %10s" % ('Total','Per run') diff --git a/IPython/Shell.py b/IPython/Shell.py index 5454f7b..2dd9dac 100644 --- a/IPython/Shell.py +++ b/IPython/Shell.py @@ -292,17 +292,19 @@ if HAS_CTYPES: """raises the exception, performs cleanup if needed""" if not inspect.isclass(exctype): raise TypeError("Only types can be raised (not instances)") - res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, + # Explicit cast to c_long is necessary for 64-bit support: + # See https://bugs.launchpad.net/ipython/+bug/237073 + res = ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(tid), ctypes.py_object(exctype)) if res == 0: raise ValueError("invalid thread id") elif res != 1: - # """if it returns a number greater than one, you're in trouble, - # and you should call it again with exc=NULL to revert the effect""" + # If it returns a number greater than one, you're in trouble, + # and you should call it again with exc=NULL to revert the effect ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0) raise SystemError("PyThreadState_SetAsyncExc failed") - def sigint_handler (signum,stack_frame): + def sigint_handler(signum,stack_frame): """Sigint handler for threaded apps. This is a horrible hack to pass information about SIGINT _without_ @@ -321,7 +323,7 @@ if HAS_CTYPES: Term.cout.flush() else: - def sigint_handler (signum,stack_frame): + def sigint_handler(signum,stack_frame): """Sigint handler for threaded apps. This is a horrible hack to pass information about SIGINT _without_ diff --git a/IPython/background_jobs.py b/IPython/background_jobs.py index e418aaa..c5998c3 100644 --- a/IPython/background_jobs.py +++ b/IPython/background_jobs.py @@ -248,7 +248,7 @@ class BackgroundJobManager: self._update_status() new_comp = self._group_report(self._comp_report,'Completed') new_dead = self._group_report(self._dead_report, - 'Dead, call job.traceback() for details') + 'Dead, call jobs.traceback() for details') self._comp_report[:] = [] self._dead_report[:] = [] return new_comp or new_dead @@ -340,7 +340,7 @@ class BackgroundJobBase(threading.Thread): stat_created = 'Created'; stat_created_c = 0 stat_running = 'Running'; stat_running_c = 1 stat_completed = 'Completed'; stat_completed_c = 2 - stat_dead = 'Dead (Exception), call job.traceback() for details' + stat_dead = 'Dead (Exception), call jobs.traceback() for details' stat_dead_c = -1 def __init__(self): @@ -391,7 +391,7 @@ class BackgroundJobBase(threading.Thread): self.status = BackgroundJobBase.stat_dead self.stat_code = BackgroundJobBase.stat_dead_c self.finished = None - self.result = ('') + self.result = ('') self._tb = self._make_tb() else: self.status = BackgroundJobBase.stat_completed