[IPython-dev] Weird KeyboardInterrupts

Ville M. Vainio vivainio at gmail.com
Wed May 2 11:29:14 EDT 2007


On 5/2/07, Fernando Perez <fperez.net at gmail.com> wrote:

> On 5/2/07, Ville M. Vainio <vivainio at gmail.com> wrote:
> > I've been getting numerous ipython crash reports that indicate
> > "KeyboardInterrupt" as the problem, yet the users claim to not have
> > pressed ctrl+c. Anyone have this happening right now?
>
> Can you post one such traceback so we can have a look?

Attached.

It seems to be a part of a "missing readline" exception handling, but
turns to KeyboardInterrupt.

-- 
Ville M. Vainio - vivainio.googlepages.com
blog=360.yahoo.com/villevainio - g[mail | talk]='vivainio'
-------------- next part --------------
***************************************************************************

IPython post-mortem report

IPython version: 0.8.0 

SVN revision   : 2191 

Platform info  : os.name -> posix, sys.platform -> darwin

***************************************************************************

Current user configuration structure:

{'Version': 0,
 '__allownew': False,
 'alias': [],
 'args': [],
 'autocall': 1,
 'autoedit_syntax': 0,
 'autoindent': 1,
 'automagic': 1,
 'banner': 1,
 'c': '',
 'cache_size': 1000,
 'classic': 0,
 'color_info': 1,
 'colors': 'NoColor',
 'confirm_exit': 1,
 'debug': 0,
 'deep_reload': 0,
 'editor': 'vi',
 'embedded': False,
 'execfile': [],
 'execute': [''],
 'gthread': 0,
 'help': 0,
 'ignore': 0,
 'import_all': [],
 'import_mod': [],
 'import_some': [[]],
 'include': [],
 'ipythondir': '/Users/veged/.ipython',
 'log': 0,
 'logfile': '',
 'logplay': '',
 'magic_docstrings': 0,
 'messages': 1,
 'multi_line_specials': 1,
 'nosep': 0,
 'object_info_string_level': 0,
 'opts': Struct({'__allownew': True}),
 'pdb': 0,
 'pprint': 1,
 'profile': '',
 'prompt_in1': 'In [\\#]: ',
 'prompt_in2': '   .\\D.: ',
 'prompt_out': 'Out[\\#]: ',
 'prompts_pad_left': 1,
 'pylab': 0,
 'pylab_import_all': 1,
 'q4thread': 0,
 'qthread': 0,
 'quick': 0,
 'quiet': 0,
 'rcfile': 'ipythonrc',
 'readline': 1,
 'readline_merge_completions': 1,
 'readline_omit__names': 0,
 'readline_parse_and_bind': ['tab: complete',
                             '"\\C-l": possible-completions',
                             'set show-all-if-ambiguous on',
                             '"\\C-o": tab-insert',
                             '"\\M-i": "    "',
                             '"\\M-o": "\\d\\d\\d\\d"',
                             '"\\M-I": "\\d\\d\\d\\d"',
                             '"\\C-r": reverse-search-history',
                             '"\\C-s": forward-search-history',
                             '"\\C-p": history-search-backward',
                             '"\\C-n": history-search-forward',
                             '"\\e[A": history-search-backward',
                             '"\\e[B": history-search-forward',
                             '"\\C-k": kill-line',
                             '"\\C-u": unix-line-discard'],
 'readline_remove_delims': '-/~',
 'screen_length': -2,
 'separate_in': '\n',
 'separate_out': '',
 'separate_out2': '',
 'system_header': 'IPython system call: ',
 'system_verbose': 0,
 'term_title': 1,
 'tk': 0,
 'upgrade': 0,
 'wildcards_case_sensitive': 1,
 'wthread': 0,
 'wxversion': '0',
 'xmode': 'Context'}

***************************************************************************

Crash traceback:

---------------------------------------------------------------------------
<type 'exceptions.KeyboardInterrupt'>  Python 2.5: /opt/local/bin/python2.5
                                                   Fri Apr 13 13:44:32 2007
A problem occured executing Python code.  Here is the sequence of function
calls leading up to the error, with the most recent (innermost) call last.

/opt/local/bin/ipython in <module>()
     12 IPython.Shell.IPShell().mainloop(sys_exit=1)
     13 
     14 [or simply IPython.Shell.IPShell().mainloop(1) ]
     15 
     16 and IPython will be your working environment when you start python. The final
     17 sys.exit() call will make python exit transparently when IPython finishes, so
     18 you don't have an extra prompt to get out of.
     19 
     20 This is probably useful to developers who manage multiple Python versions and
     21 don't want to have correspondingly multiple IPython versions. Note that in
     22 this mode, there is no way to pass IPython any command-line options, as those
     23 are trapped first by Python itself.
     24 """
     25 
     26 import IPython
---> 27 IPython.Shell.start().mainloop()
        global IPython.Shell.start.mainloop = undefined
     28 
     29 
     30 
     31 
     32 
     33 
     34 
     35 
     36 
     37 
     38 
     39 
     40 
     41 
     42 

/opt/local/lib/python2.5/site-packages/IPython/Shell.py in mainloop(self=<IPython.Shell.IPShell instance at 0x55aad0>, sys_exit=0, banner=None)
     62 #-----------------------------------------------------------------------------
     63 # This class is trivial now, but I want to have it in to publish a clean
     64 # interface. Later when the internals are reorganized, code that uses this
     65 # shouldn't have to change.
     66 
     67 class IPShell:
     68     """Create an IPython instance."""
     69     
     70     def __init__(self,argv=None,user_ns=None,user_global_ns=None,
     71                  debug=1,shell_class=InteractiveShell):
     72         self.IP = make_IPython(argv,user_ns=user_ns,
     73                                user_global_ns=user_global_ns,
     74                                debug=debug,shell_class=shell_class)
     75 
     76     def mainloop(self,sys_exit=0,banner=None):
---> 77         self.IP.mainloop(banner)
        self.IP.mainloop = <bound method InteractiveShell.mainloop of <IPython.iplib.InteractiveShell object at 0x55b6d0>>
        banner = None
     78         if sys_exit:
     79             sys.exit()
     80 
     81 #-----------------------------------------------------------------------------
     82 class IPShellEmbed:
     83     """Allow embedding an IPython shell into a running program.
     84 
     85     Instances of this class are callable, with the __call__ method being an
     86     alias to the embed() method of an InteractiveShell instance.
     87 
     88     Usage (see also the example-embed.py file for a running example):
     89 
     90     ipshell = IPShellEmbed([argv,banner,exit_msg,rc_override])
     91 
     92     - argv: list containing valid command-line options for IPython, as they

/opt/local/lib/python2.5/site-packages/IPython/iplib.py in mainloop(self=<IPython.iplib.InteractiveShell object at 0x55b6d0>, banner="Python 2.5 (r25:51908, Mar  4 2007, 03:45:52) \nT...ut 'object'. ?object also works, ?? prints more.\n")
   1511 
   1512         If an optional banner argument is given, it will override the
   1513         internally created default banner."""
   1514 
   1515         if self.rc.c:  # Emulate Python's -c option
   1516             self.exec_init_cmd()
   1517         if banner is None:
   1518             if not self.rc.banner:
   1519                 banner = ''
   1520             # banner is string? Use it directly!
   1521             elif isinstance(self.rc.banner,basestring):
   1522                 banner = self.rc.banner
   1523             else:                
   1524                 banner = self.BANNER+self.banner2
   1525 
-> 1526         self.interact(banner)
        self.interact = <bound method InteractiveShell.interact of <IPython.iplib.InteractiveShell object at 0x55b6d0>>
        banner = 'Python 2.5 (r25:51908, Mar  4 2007, 03:45:52) \nType "copyright", "credits" or "license" for more information.\n\nIPython 0.8.0 -- An enhanced Interactive Python.\n?       -> Introduction to IPython\'s features.\n%magic  -> Information about IPython\'s \'magic\' % functions.\nhelp    -> Python\'s own help system.\nobject? -> Details about \'object\'. ?object also works, ?? prints more.\n'
   1527 
   1528     def exec_init_cmd(self):
   1529         """Execute a command given at the command line.
   1530 
   1531         This emulates Python's -c option."""
   1532 
   1533         #sys.argv = ['-c']
   1534         self.push(self.rc.c)
   1535 
   1536     def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0):
   1537         """Embeds IPython into a running python program.
   1538 
   1539         Input:
   1540 
   1541           - header: An optional header message can be specified.

/opt/local/lib/python2.5/site-packages/IPython/iplib.py in interact(self=<IPython.iplib.InteractiveShell object at 0x55b6d0>, banner="Python 2.5 (r25:51908, Mar  4 2007, 03:45:52) \nT...ut 'object'. ?object also works, ?? prints more.\n")
   1656                     self.indent_current_nsp = 0
   1657                 more = 0
   1658             except EOFError:
   1659                 if self.autoindent:
   1660                     self.readline_startup_hook(None)
   1661                 self.write('\n')
   1662                 self.exit()
   1663             except bdb.BdbQuit:
   1664                 warn('The Python debugger has exited with a BdbQuit exception.\n'
   1665                      'Because of how pdb handles the stack, it is impossible\n'
   1666                      'for IPython to properly format this particular exception.\n'
   1667                      'IPython will resume normal operation.')
   1668             except:
   1669                 # exceptions here are VERY RARE, but they can be triggered
   1670                 # asynchronously by signal handlers, for example.
-> 1671                 self.showtraceback()
        self.showtraceback = <bound method InteractiveShell.showtraceback of <IPython.iplib.InteractiveShell object at 0x55b6d0>>
   1672             else:
   1673                 more = self.push(line)
   1674                 if (self.SyntaxTB.last_syntax_error and
   1675                     self.rc.autoedit_syntax):
   1676                     self.edit_syntax_error()
   1677             
   1678         # We are off again...
   1679         __builtin__.__dict__['__IPYTHON__active'] -= 1
   1680 
   1681     def excepthook(self, etype, value, tb):
   1682       """One more defense for GUI apps that call sys.excepthook.
   1683 
   1684       GUI frameworks like wxPython trap exceptions and call
   1685       sys.excepthook themselves.  I guess this is a feature that
   1686       enables them to keep running after exceptions that would

/opt/local/lib/python2.5/site-packages/IPython/iplib.py in showtraceback(self=<IPython.iplib.InteractiveShell object at 0x55b6d0>, exc_tuple=None, filename=None, tb_offset=None)
   1489 
   1490         if etype is SyntaxError:
   1491             self.showsyntaxerror(filename)
   1492         else:
   1493             # WARNING: these variables are somewhat deprecated and not
   1494             # necessarily safe to use in a threaded environment, but tools
   1495             # like pdb depend on their existence, so let's set them.  If we
   1496             # find problems in the field, we'll need to revisit their use.
   1497             sys.last_type = etype
   1498             sys.last_value = value
   1499             sys.last_traceback = tb
   1500 
   1501             if etype in self.custom_exceptions:
   1502                 self.CustomTB(etype,value,tb)
   1503             else:
-> 1504                 self.InteractiveTB(etype,value,tb,tb_offset=tb_offset)
        self.InteractiveTB = <IPython.ultraTB.AutoFormattedTB instance at 0x11923f0>
        etype = <type 'exceptions.AttributeError'>
        value = AttributeError("'NoneType' object has no attribute 'set_completer'",)
        tb = <traceback object at 0x11bc850>
        tb_offset = None
   1505                 if self.InteractiveTB.call_pdb and self.has_readline:
   1506                     # pdb mucks up readline, fix it back
   1507                     self.set_completer()
   1508 
   1509     def mainloop(self,banner=None):
   1510         """Creates the local namespace and starts the mainloop.
   1511 
   1512         If an optional banner argument is given, it will override the
   1513         internally created default banner."""
   1514 
   1515         if self.rc.c:  # Emulate Python's -c option
   1516             self.exec_init_cmd()
   1517         if banner is None:
   1518             if not self.rc.banner:
   1519                 banner = ''

/opt/local/lib/python2.5/site-packages/IPython/ultraTB.py in __call__(self=<IPython.ultraTB.AutoFormattedTB instance at 0x11923f0>, etype=<type 'exceptions.AttributeError'>, evalue=AttributeError("'NoneType' object has no attribute 'set_completer'",), etb=<traceback object at 0x11bc850>, out=<IPython.genutils.IOStream instance at 0x5ce1c0>, tb_offset=None)
    856           - out: an open file-like object to direct output to.
    857 
    858           - tb_offset: the number of frames to skip over in the stack, on a
    859           per-call basis (this overrides temporarily the instance's tb_offset
    860           given at initialization time.  """
    861         
    862         if out is None:
    863             out = Term.cerr
    864         Term.cout.flush()
    865         out.flush()
    866         if tb_offset is not None:
    867             tb_offset, self.tb_offset = self.tb_offset, tb_offset
    868             print >> out, self.text(etype, evalue, etb)
    869             self.tb_offset = tb_offset
    870         else:
--> 871             print >> out, self.text(etype, evalue, etb)
        out = <IPython.genutils.IOStream instance at 0x5ce1c0>
        self.text = <bound method AutoFormattedTB.text of <IPython.ultraTB.AutoFormattedTB instance at 0x11923f0>>
        etype = <type 'exceptions.AttributeError'>
        evalue = AttributeError("'NoneType' object has no attribute 'set_completer'",)
        etb = <traceback object at 0x11bc850>
    872         self.debugger()
    873 
    874     def text(self,etype=None,value=None,tb=None,context=5,mode=None):
    875         if etype is None:
    876             etype,value,tb = sys.exc_info()
    877         self.tb = tb
    878         return FormattedTB.text(self,etype,value,tb,context=5,mode=mode)
    879 
    880 #---------------------------------------------------------------------------
    881 # A simple class to preserve Nathan's original functionality.
    882 class ColorTB(FormattedTB):
    883     """Shorthand to initialize a FormattedTB in Linux colors mode."""
    884     def __init__(self,color_scheme='Linux',call_pdb=0):
    885         FormattedTB.__init__(self,color_scheme=color_scheme,
    886                              call_pdb=call_pdb)

/opt/local/lib/python2.5/site-packages/IPython/ultraTB.py in text(self=<IPython.ultraTB.AutoFormattedTB instance at 0x11923f0>, etype=<type 'exceptions.AttributeError'>, value=AttributeError("'NoneType' object has no attribute 'set_completer'",), tb=<traceback object at 0x11bc850>, context=5, mode=None)
    863             out = Term.cerr
    864         Term.cout.flush()
    865         out.flush()
    866         if tb_offset is not None:
    867             tb_offset, self.tb_offset = self.tb_offset, tb_offset
    868             print >> out, self.text(etype, evalue, etb)
    869             self.tb_offset = tb_offset
    870         else:
    871             print >> out, self.text(etype, evalue, etb)
    872         self.debugger()
    873 
    874     def text(self,etype=None,value=None,tb=None,context=5,mode=None):
    875         if etype is None:
    876             etype,value,tb = sys.exc_info()
    877         self.tb = tb
--> 878         return FormattedTB.text(self,etype,value,tb,context=5,mode=mode)
        global FormattedTB.text = <unbound method FormattedTB.text>
        self = <IPython.ultraTB.AutoFormattedTB instance at 0x11923f0>
        etype = <type 'exceptions.AttributeError'>
        value = AttributeError("'NoneType' object has no attribute 'set_completer'",)
        tb = <traceback object at 0x11bc850>
        context = 5
        mode = None
    879 
    880 #---------------------------------------------------------------------------
    881 # A simple class to preserve Nathan's original functionality.
    882 class ColorTB(FormattedTB):
    883     """Shorthand to initialize a FormattedTB in Linux colors mode."""
    884     def __init__(self,color_scheme='Linux',call_pdb=0):
    885         FormattedTB.__init__(self,color_scheme=color_scheme,
    886                              call_pdb=call_pdb)
    887 
    888 #----------------------------------------------------------------------------
    889 # module testing (minimal)
    890 if __name__ == "__main__":
    891     def spam(c, (d, e)):
    892         x = c + d
    893         y = c * d

/opt/local/lib/python2.5/site-packages/IPython/ultraTB.py in text(self=<IPython.ultraTB.AutoFormattedTB instance at 0x11923f0>, etype=<type 'exceptions.AttributeError'>, value=AttributeError("'NoneType' object has no attribute 'set_completer'",), tb=<traceback object at 0x11bc850>, context=5, mode='Context')
    784         if tb:
    785             return traceback.extract_tb(tb)
    786         else:
    787             return None
    788 
    789     def text(self, etype, value, tb,context=5,mode=None):
    790         """Return formatted traceback.
    791 
    792         If the optional mode parameter is given, it overrides the current
    793         mode."""
    794 
    795         if mode is None:
    796             mode = self.mode
    797         if mode in self.verbose_modes:
    798             # verbose modes need a full traceback
--> 799             return VerboseTB.text(self,etype, value, tb,context=5)
        global VerboseTB.text = <unbound method VerboseTB.text>
        self = <IPython.ultraTB.AutoFormattedTB instance at 0x11923f0>
        etype = <type 'exceptions.AttributeError'>
        value = AttributeError("'NoneType' object has no attribute 'set_completer'",)
        tb = <traceback object at 0x11bc850>
        context = 5
    800         else:
    801             # We must check the source cache because otherwise we can print
    802             # out-of-date source code.
    803             linecache.checkcache()
    804             # Now we can extract and format the exception
    805             elist = self._extract_tb(tb)
    806             if len(elist) > self.tb_offset:
    807                 del elist[:self.tb_offset]
    808             return ListTB.text(self,etype,value,elist)
    809 
    810     def set_mode(self,mode=None):
    811         """Switch to the desired mode.
    812 
    813         If mode is not specified, cycles through the available modes."""
    814 

/opt/local/lib/python2.5/site-packages/IPython/ultraTB.py in text(self=<IPython.ultraTB.AutoFormattedTB instance at 0x11923f0>, etype=<type 'exceptions.AttributeError'>, evalue=AttributeError("'NoneType' object has no attribute 'set_completer'",), etb=<traceback object at 0x11bc850>, context=5)
    600                     raise IndexError
    601             # we need to store a bit of state in the tokenizer to build
    602             # dotted names
    603             tokeneater.name_cont = False
    604 
    605             def linereader(file=file, lnum=[lnum], getline=linecache.getline):
    606                 line = getline(file, lnum[0])
    607                 lnum[0] += 1
    608                 return line
    609 
    610             # Build the list of names on this line of code where the exception
    611             # occurred.
    612             try:
    613                 # This builds the names list in-place by capturing it from the
    614                 # enclosing scope.
--> 615                 tokenize.tokenize(linereader, tokeneater)
        global tokenize.tokenize = <function tokenize at 0x5c20f0>
        linereader = <function linereader at 0x1225570>
        global tokeneater = undefined
    616             except IndexError:
    617                 # signals exit of tokenizer
    618                 pass
    619             except tokenize.TokenError,msg:
    620                 _m = ("An unexpected error occurred while tokenizing input\n"
    621                       "The following traceback may be corrupted or invalid\n"
    622                       "The error message is: %s\n" % msg)
    623                 error(_m)
    624             
    625             # prune names list of duplicates, but keep the right order
    626             unique_names = uniq_stable(names)
    627 
    628             # Start loop over vars
    629             lvals = []
    630             if self.include_vars:

/opt/local/lib/python2.5/tokenize.py in tokenize(readline=<function linereader at 0x1225570>, tokeneater=<function tokeneater at 0x1225c70>)
    138 
    139 def tokenize(readline, tokeneater=printtoken):
    140     """
    141     The tokenize() function accepts two parameters: one representing the
    142     input stream, and one providing an output mechanism for tokenize().
    143 
    144     The first parameter, readline, must be a callable object which provides
    145     the same interface as the readline() method of built-in file objects.
    146     Each call to the function should return one line of input as a string.
    147 
    148     The second parameter, tokeneater, must also be a callable object. It is
    149     called once for each token, with five arguments, corresponding to the
    150     tuples generated by generate_tokens().
    151     """
    152     try:
--> 153         tokenize_loop(readline, tokeneater)
        global tokenize_loop = <function tokenize_loop at 0x5c2130>
        readline = <function linereader at 0x1225570>
        tokeneater = <function tokeneater at 0x1225c70>
    154     except StopTokenizing:
    155         pass
    156 
    157 # backwards compatible interface
    158 def tokenize_loop(readline, tokeneater):
    159     for token_info in generate_tokens(readline):
    160         tokeneater(*token_info)
    161 
    162 
    163 def untokenize(iterable):
    164     """Transform tokens back into Python source code.
    165 
    166     Each element returned by the iterable must be a token sequence
    167     with at least two elements, a token number and token value.
    168 

/opt/local/lib/python2.5/tokenize.py in tokenize_loop(readline=<function linereader at 0x1225570>, tokeneater=<function tokeneater at 0x1225c70>)
    144     The first parameter, readline, must be a callable object which provides
    145     the same interface as the readline() method of built-in file objects.
    146     Each call to the function should return one line of input as a string.
    147 
    148     The second parameter, tokeneater, must also be a callable object. It is
    149     called once for each token, with five arguments, corresponding to the
    150     tuples generated by generate_tokens().
    151     """
    152     try:
    153         tokenize_loop(readline, tokeneater)
    154     except StopTokenizing:
    155         pass
    156 
    157 # backwards compatible interface
    158 def tokenize_loop(readline, tokeneater):
--> 159     for token_info in generate_tokens(readline):
        token_info = (5, '        ', (1, 0), (1, 8), '        self.readline.set_completer(self.Completer.complete)\n')
        global generate_tokens = <function generate_tokens at 0x5c21b0>
        readline = <function linereader at 0x1225570>
    160         tokeneater(*token_info)
    161 
    162 
    163 def untokenize(iterable):
    164     """Transform tokens back into Python source code.
    165 
    166     Each element returned by the iterable must be a token sequence
    167     with at least two elements, a token number and token value.
    168 
    169     Round-trip invariant:
    170         # Output text will tokenize the back to the input
    171         t1 = [tok[:2] for tok in generate_tokens(f.readline)]
    172         newcode = untokenize(t1)
    173         readline = iter(newcode.splitlines(1)).next
    174         t2 = [tok[:2] for tokin generate_tokens(readline)]

/opt/local/lib/python2.5/tokenize.py in generate_tokens(readline=<function linereader at 0x1225570>)
    272                 yield (INDENT, line[:pos], (lnum, 0), (lnum, pos), line)
    273             while column < indents[-1]:
    274                 if column not in indents:
    275                     raise IndentationError(
    276                         "unindent does not match any outer indentation level",
    277                         ("<tokenize>", lnum, pos, line))
    278                 indents = indents[:-1]
    279                 yield (DEDENT, '', (lnum, pos), (lnum, pos), line)
    280 
    281         else:                                  # continued statement
    282             if not line:
    283                 raise TokenError, ("EOF in multi-line statement", (lnum, 0))
    284             continued = 0
    285 
    286         while pos < max:
--> 287             pseudomatch = pseudoprog.match(line, pos)
        pseudomatch = undefined
        global pseudoprog.match = <built-in method match of _sre.SRE_Pattern object at 0x1864e00>
        line = '        self.readline.set_completer(self.Completer.complete)\n'
        pos = 8
    288             if pseudomatch:                                # scan for tokens
    289                 start, end = pseudomatch.span(1)
    290                 spos, epos, pos = (lnum, start), (lnum, end), end
    291                 token, initial = line[start:end], line[start]
    292 
    293                 if initial in numchars or \
    294                    (initial == '.' and token != '.'):      # ordinary number
    295                     yield (NUMBER, token, spos, epos, line)
    296                 elif initial in '\r\n':
    297                     yield (parenlev > 0 and NL or NEWLINE,
    298                                token, spos, epos, line)
    299                 elif initial == '#':
    300                     yield (COMMENT, token, spos, epos, line)
    301                 elif token in triple_quoted:
    302                     endprog = endprogs[token]

<type 'exceptions.KeyboardInterrupt'>: 

***************************************************************************

History of session input:

*** Last line of input (may not be in above history):


More information about the IPython-dev mailing list