? + plot() Command B0rks QTConsole Strangely #586

Closed
meawoppl opened this Issue Jul 16, 2011 · 3 comments

Comments

Projects
None yet
3 participants
@meawoppl

In the qtconsole, when I get help on something (not necessarily a valid object) enclosed in the plot command, the interperater hangs (no restart option) and a lot of stuff is generated at the console:

Basically . . .

In [1]: from pylab import *
In [2]: plot?
In [3]: a?
Object `a` not found.
In [4]: plot(a?
[Hang and shell output below, no txt crash file generated either as far as I can tell . . .]

/usr/local/lib/python2.7/dist-packages/IPython/frontend/qt/console/frontend_widget.pyc in _event_filter_console_keypress(self=, event=)
    253 
    254             # Smart backspace: remove four characters in one backspace if:
    255             # 1) everything left of the cursor is whitespace
    256             # 2) the four characters immediately left of the cursor are spaces
    257             if key == QtCore.Qt.Key_Backspace:
    258                 col = self._get_input_buffer_cursor_column()
    259                 cursor = self._control.textCursor()
    260                 if col > 3 and not cursor.hasSelection():
    261                     text = self._get_input_buffer_cursor_line()[:col]
    262                     if text.endswith('    ') and not text.strip():
    263                         cursor.movePosition(QtGui.QTextCursor.Left,
    264                                             QtGui.QTextCursor.KeepAnchor, 4)
    265                         cursor.removeSelectedText()
    266                         return True
    267 
--> 268         return super(FrontendWidget, self)._event_filter_console_keypress(event)
    269 
    270     def _insert_continuation_prompt(self, cursor):
    271         """ Reimplemented for auto-indentation.
    272         """
    273         super(FrontendWidget, self)._insert_continuation_prompt(cursor)
    274         cursor.insertText(' ' * self._input_splitter.indent_spaces)
    275 
    276     #---------------------------------------------------------------------------
    277     # 'BaseFrontendMixin' abstract interface
    278     #---------------------------------------------------------------------------
    279 
    280     def _handle_complete_reply(self, rep):
    281         """ Handle replies for tab completion.
    282         """
    283         cursor = self._get_cursor()

/usr/local/lib/python2.7/dist-packages/IPython/frontend/qt/console/console_widget.pyc in _event_filter_console_keypress(self=, event=)
    968                     self._append_plain_text('\n')
    969                     self._reading = False
    970                     if self._reading_callback:
    971                         self._reading_callback()
    972 
    973                 # If the input buffer is a single line or there is only
    974                 # whitespace after the cursor, execute. Otherwise, split the
    975                 # line with a continuation prompt.
    976                 elif not self._executing:
    977                     cursor.movePosition(QtGui.QTextCursor.End,
    978                                         QtGui.QTextCursor.KeepAnchor)
    979                     at_end = len(cursor.selectedText().strip()) == 0
    980                     single_line = (self._get_end_cursor().blockNumber() ==
    981                                    self._get_prompt_cursor().blockNumber())
    982                     if (at_end or shift_down or single_line) and not ctrl_down:
--> 983                         self.execute(interactive = not shift_down)
    984                     else:
    985                         # Do this inside an edit block for clean undo/redo.
    986                         cursor.beginEditBlock()
    987                         cursor.setPosition(position)
    988                         cursor.insertText('\n')
    989                         self._insert_continuation_prompt(cursor)
    990                         cursor.endEditBlock()
    991 
    992                         # Ensure that the whole input buffer is visible.
    993                         # FIXME: This will not be usable if the input buffer is
    994                         # taller than the console widget.
    995                         self._control.moveCursor(QtGui.QTextCursor.End)
    996                         self._control.setTextCursor(cursor)
    997 
    998         #------ Control/Cmd modifier -------------------------------------------

/usr/local/lib/python2.7/dist-packages/IPython/frontend/qt/console/history_console_widget.pyc in execute(self=, source=None, hidden=False, interactive=True)
     30         self._history_edits = {}
     31         self._history_index = 0
     32         self._history_prefix = ''
     33 
     34     #---------------------------------------------------------------------------
     35     # 'ConsoleWidget' public interface
     36     #---------------------------------------------------------------------------
     37 
     38     def execute(self, source=None, hidden=False, interactive=False):
     39         """ Reimplemented to the store history.
     40         """
     41         if not hidden:
     42             history = self.input_buffer if source is None else source
     43 
     44         executed = super(HistoryConsoleWidget, self).execute(
---> 45             source, hidden, interactive)
        global startswithR = undefined
        global t = undefined
        global _store_editsR = undefined
        global R = undefined
        global prefixt = undefined
        global indext = undefined
        global replaceR = undefined
        global s = undefined
        global usr = undefined
        global local = undefined
        global lib = undefined
        global python2 = undefined
        global dist = undefined
        global packages = undefined
        global IPython = undefined
        global frontend = undefined
        global qt = undefined
        global console = undefined
        global history_console_widget.pyR = undefined
        global c = undefined
        global C = undefined
        global j = undefined
        global xN = undefined
        global k = undefined
        global r_ = undefined
        global d = undefined
        global r = undefined
        global Pq = undefined
        global q = undefined
        global W = undefined
        global _ = undefined
        global n = undefined
        global S = undefined
        global If = undefined
        global possible = undefined
        global set = undefined
        global the = undefined
        global input = undefined
        global buffer = undefined
        global to = undefined
        global a = undefined
        global subsequent = undefined
        history = u'plot(a?'
        global item. = undefined
     46 
     47         if executed and not hidden:
     48             # Save the command unless it was an empty string or was identical 
     49             # to the previous command.
     50             history = history.rstrip()
     51             if history and (not self._history or self._history[-1] != history):
     52                 self._history.append(history)
     53 
     54             # Emulate readline: reset all history edits.
     55             self._history_edits = {}
     56 
     57             # Move the history index to the most recent item.
     58             self._history_index = len(self._history)
     59 
     60         return executed

/usr/local/lib/python2.7/dist-packages/IPython/frontend/qt/console/console_widget.pyc in execute(self=, source=u'plot(a?\n', hidden=False, interactive=True)
    453         # WARNING: The order in which things happen here is very particular, in
    454         # large part because our syntax highlighting is fragile. If you change
    455         # something, test carefully!
    456 
    457         # Decide what to execute.
    458         if source is None:
    459             source = self.input_buffer
    460             if not hidden:
    461                 # A newline is appended later, but it should be considered part
    462                 # of the input buffer.
    463                 source += '\n'
    464         elif not hidden:
    465             self.input_buffer = source
    466             
    467         # Execute the source or show a continuation prompt if it is incomplete.
--> 468         complete = self._is_complete(source, interactive)
        global j = undefined
        global d = undefined
        global t = undefined
    469         if hidden:
    470             if complete:
    471                 self._execute(source, hidden)
    472             else:
    473                 error = 'Incomplete noninteractive input: "%s"'
    474                 raise RuntimeError(error % source)                
    475         else:
    476             if complete:
    477                 self._append_plain_text('\n')
    478                 self._input_buffer_executing = self.input_buffer
    479                 self._executing = True
    480                 self._prompt_finished()
    481 
    482                 # The maximum block count is only in effect during execution.
    483                 # This ensures that _prompt_pos does not become invalid due to

/usr/local/lib/python2.7/dist-packages/IPython/frontend/qt/console/frontend_widget.pyc in _is_complete(self=, source=u'plot(a?\n', interactive=True)
    159         text = self._control.textCursor().selection().toPlainText()
    160         if text:
    161             lines = map(transform_classic_prompt, text.splitlines())
    162             text = '\n'.join(lines)
    163             QtGui.QApplication.clipboard().setText(text)
    164 
    165     #---------------------------------------------------------------------------
    166     # 'ConsoleWidget' abstract interface
    167     #---------------------------------------------------------------------------
    168 
    169     def _is_complete(self, source, interactive):
    170         """ Returns whether 'source' can be completely processed and a new
    171             prompt created. When triggered by an Enter/Return key press,
    172             'interactive' is True; otherwise, it is False.
    173         """
--> 174         complete = self._input_splitter.push(source)
        global N = undefined
        global R = undefined
        global R0 = undefined
        global R1 = undefined
        global t = undefined
        global SignalR = undefined
        global floatR = undefined
        global objectRy = undefined
        global R3 = undefined
        global R6 = undefined
        global R7 = undefined
        global RD = undefined
        global RC = undefined
        global Rn = undefined
        global Rt = undefined
        global RX = undefined
        global sU = undefined
        global usr = undefined
        global local = undefined
        global lib = undefined
        global python2 = undefined
        global dist = undefined
        global packages = undefined
        global IPython = undefined
        global frontend = undefined
        global qt = undefined
        global console = undefined
        global frontend_widget.pyR2 = undefined
        global J = undefined
        global sd = undefined
        global __future__R = undefined
        global collectionsR = undefined
        global pygments.lexersR = undefined
        global IPython.external.qtR = undefined
        global IPython.core.inputsplitterR = undefined
        global IPython.core.oinspectR = undefined
        global IPython.frontend.qt.base_frontend_mixinR = undefined
        global IPython.utils.traitletsR = undefined
        global bracket_matcherR = undefined
        global call_tip_widgetR = undefined
        global completion_lexerR = undefined
        global history_console_widgetR = undefined
        global pygments_highlighterR = undefined
        global R2 = undefined
        global frontend_widget.pyt = undefined
        global module = undefined
        global s = undefined
    175         if interactive:
    176             complete = not self._input_splitter.push_accepts_more()
    177         return complete
    178 
    179     def _execute(self, source, hidden):
    180         """ Execute 'source'. If 'hidden', do not show any output.
    181 
    182         See parent class :meth:`execute` docstring for full details.
    183         """
    184         msg_id = self.kernel_manager.shell_channel.execute(source, hidden)
    185         self._request_info['execute'] = self._ExecutionRequest(msg_id, 'user')
    186         self._hidden = hidden
    187         if not hidden:
    188             self.executing.emit(source)
    189         

/usr/local/lib/python2.7/dist-packages/IPython/core/inputsplitter.pyc in push(self=, lines=u'plot(a?\n')
    866             changed_input_mode = True
    867             saved_input_mode = 'cell'
    868             self.input_mode = 'line'
    869 
    870         # Store raw source before applying any transformations to it.  Note
    871         # that this must be done *after* the reset() call that would otherwise
    872         # flush the buffer.
    873         self._store(lines, self._buffer_raw, 'source_raw')
    874         
    875         try:
    876             push = super(IPythonInputSplitter, self).push
    877             for line in lines_list:
    878                 if self._is_complete or not self._buffer or \
    879                    (self._buffer and self._buffer[-1].rstrip().endswith(':')):
    880                     for f in transforms:
--> 881                         line = f(line)
    882 
    883                 out = push(line)
    884         finally:
    885             if changed_input_mode:
    886                 self.input_mode = saved_input_mode
    887         return out

/usr/local/lib/python2.7/dist-packages/IPython/core/inputsplitter.pyc in transform_help_end(line=u'plot(a?')
    680         tpl = '%sget_ipython().magic(u"%s %s", next_input=%s)'
    681         return tpl % (lspace, method, target, make_quoted_expr(next_input))
    682     else:
    683         return '%sget_ipython().magic(u"%s %s")' % (lspace, method, target)
    684 
    685 _initial_space_re = re.compile(r'\s*')
    686 _help_end_re = re.compile(r"""(%?
    687                               [a-zA-Z_*][a-zA-Z0-9_*]*       # Variable name
    688                               (\.[a-zA-Z_*][a-zA-Z0-9_*]*)*   # .etc.etc
    689                               )
    690                               (\?\??)$                       # ? or ??""",
    691                               re.VERBOSE)
    692 def transform_help_end(line):
    693     """Translate lines with ?/?? at the end"""
    694     m = _help_end_re.search(line)
--> 695     if m is None or has_comment(line):
    696         return line
    697     target = m.group(1)
    698     esc = m.group(3)
    699     lspace = _initial_space_re.match(line).group(0)
    700     newline = _make_help_call(target, esc, lspace)
    701     
    702     # If we're mid-command, put it back on the next prompt for the user.
    703     next_input = line.rstrip('?') if line.strip() != m.group(0) else None
    704         
    705     return _make_help_call(target, esc, lspace, next_input)
    706 
    707 
    708 class EscapedTransformer(object):
    709     """Class to transform lines that are explicitly escaped out."""
    710 

/usr/local/lib/python2.7/dist-packages/IPython/core/inputsplitter.pyc in has_comment(src=u'plot(a?')
    161 def has_comment(src):
    162     """Indicate whether an input line has (i.e. ends in, or is) a comment.
    163     
    164     This uses tokenize, so it can distinguish comments from # inside strings.
    165     
    166     Parameters
    167     ----------
    168     src : string
    169       A single line input string.
    170     
    171     Returns
    172     -------
    173     Boolean: True if source has a comment.
    174     """
    175     readline = StringIO(src).readline
--> 176     toktypes = set(t[0] for t in tokenize.generate_tokens(readline))
        global OverflowErrort = undefined
    177     return(tokenize.COMMENT in toktypes)
    178 
    179 
    180 def get_input_encoding():
    181     """Return the default standard input encoding.
    182 
    183     If sys.stdin has no encoding, 'ascii' is returned."""
    184     # There are strange environments for which sys.stdin.encoding is None. We
    185     # ensure that a valid encoding is returned.
    186     encoding = getattr(sys.stdin, 'encoding', None)
    187     if encoding is None:
    188         encoding = 'ascii'
    189     return encoding
    190 
    191 #-----------------------------------------------------------------------------

/usr/local/lib/python2.7/dist-packages/IPython/core/inputsplitter.pyc in ((t=(52, u'?', (1, 6), (1, 7), u'plot(a?'),))
    161 def has_comment(src):
    162     """Indicate whether an input line has (i.e. ends in, or is) a comment.
    163     
    164     This uses tokenize, so it can distinguish comments from # inside strings.
    165     
    166     Parameters
    167     ----------
    168     src : string
    169       A single line input string.
    170     
    171     Returns
    172     -------
    173     Boolean: True if source has a comment.
    174     """
    175     readline = StringIO(src).readline
--> 176     toktypes = set(t[0] for t in tokenize.generate_tokens(readline))
        global OverflowErrort = undefined
    177     return(tokenize.COMMENT in toktypes)
    178 
    179 
    180 def get_input_encoding():
    181     """Return the default standard input encoding.
    182 
    183     If sys.stdin has no encoding, 'ascii' is returned."""
    184     # There are strange environments for which sys.stdin.encoding is None. We
    185     # ensure that a valid encoding is returned.
    186     encoding = getattr(sys.stdin, 'encoding', None)
    187     if encoding is None:
    188         encoding = 'ascii'
    189     return encoding
    190 
    191 #-----------------------------------------------------------------------------

/usr/lib/python2.7/tokenize.pyc in generate_tokens(readline=>)
    342                 continue
    343 
    344             if column > indents[-1]:           # count indents or dedents
    345                 indents.append(column)
    346                 yield (INDENT, line[:pos], (lnum, 0), (lnum, pos), line)
    347             while column < indents[-1]:
    348                 if column not in indents:
    349                     raise IndentationError(
    350                         "unindent does not match any outer indentation level",
    351                         ("", lnum, pos, line))
    352                 indents = indents[:-1]
    353                 yield (DEDENT, '', (lnum, pos), (lnum, pos), line)
    354 
    355         else:                                  # continued statement
    356             if not line:
--> 357                 raise TokenError, ("EOF in multi-line statement", (lnum, 0))
    358             continued = 0
    359 
    360         while pos < max:
    361             pseudomatch = pseudoprog.match(line, pos)
    362             if pseudomatch:                                # scan for tokens
    363                 start, end = pseudomatch.span(1)
    364                 spos, epos, pos = (lnum, start), (lnum, end), end
    365                 token, initial = line[start:end], line[start]
    366 
    367                 if initial in numchars or \
    368                    (initial == '.' and token != '.'):      # ordinary number
    369                     yield (NUMBER, token, spos, epos, line)
    370                 elif initial in '\r\n':
    371                     yield (NL if parenlev > 0 else NEWLINE,
    372                            token, spos, epos, line)

TokenError: ('EOF in multi-line statement', (2, 0))

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

Oops, ipython crashed. We do our best to make it stable, but...

A crash report was automatically generated with the following information:
  - A verbatim copy of the crash traceback.
  - A copy of your input history during this session.
  - Data on your current $self.app_name configuration.

It was left in the file named:
    'Crash_report_ipython.txt'
If you can email this file to the developers, the information in it will help
them in understanding and correcting the problem.

You can mail it to: $self.contact_name at fperez.net@gmail.com
with the subject 'ipython Crash Report'.

If you want to do it now, the following command will work (under Unix):
mail -s 'ipython Crash Report' fperez.net@gmail.com < Crash_report_ipython.txt

To ensure accurate tracking of this issue, please file a report about it at:
http://github.com/ipython/ipython/issues

Hit  to quit this message (your terminal may close):QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running

(this message repeats until I kill the program)

@takluyver

This comment has been minimized.

Show comment Hide comment
@takluyver

takluyver Jul 16, 2011

Owner

This is code I added recently so you can ask about objects while you're writing an expression. It seems there's a problem with tokenize. Another problem with tokenize...

Owner

takluyver commented Jul 16, 2011

This is code I added recently so you can ask about objects while you're writing an expression. It seems there's a problem with tokenize. Another problem with tokenize...

@takluyver takluyver closed this in b8d87c2 Jul 16, 2011

@takluyver

This comment has been minimized.

Show comment Hide comment
@takluyver

takluyver Jul 16, 2011

Owner

I've caught that error, so it works for me now.

Owner

takluyver commented Jul 16, 2011

I've caught that error, so it works for me now.

@minrk

This comment has been minimized.

Show comment Hide comment
@minrk

minrk Jul 16, 2011

Owner

Should be an easy fix, just catch TokenError, and return False.

Owner

minrk commented Jul 16, 2011

Should be an easy fix, just catch TokenError, and return False.

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment