ipython: IPython crash when use showtraceback with exception_only=True

Used IPython version: 7.20.0-py38hd4e2768_1

The following exception was raised:

Traceback (most recent call last):
  File "C:\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 1103, in get_records
    return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
  File "C:\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 248, in wrapped
    return f(*args, **kwargs)
  File "C:\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 281, in _fixed_getinnerframes
    records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "C:\Anaconda3\lib\inspect.py", line 1503, in getinnerframes
    frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
AttributeError: 'tuple' object has no attribute 'tb_frame'

And when this exception is caught in IPython.core.ultratb.VerboseTB.get_records, the return value is None:

def get_records(self, etb, number_of_lines_of_context, tb_offset):
    try:
        # Try the default getinnerframes and Alex's: Alex's fixes some
        # problems, but it generates empty tracebacks for console errors
        # (5 blanks lines) where none should be returned.
        return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
    except UnicodeDecodeError:
        # This can occur if a file's encoding magic comment is wrong.
        # I can't see a way to recover without duplicating a bunch of code
        # from the stdlib traceback module. --TK
        error('\nUnicodeDecodeError while processing traceback.\n')
        return None
    **except:
        # FIXME: I've been getting many crash reports from python 2.3
        # users, traceable to inspect.py.  If I can find a small test-case
        # to reproduce this, I should either write a better workaround or
        # file a bug report against inspect (if that's the real problem).
        # So far, I haven't been able to find an isolated example to
        # reproduce the problem.
        inspect_error()
        traceback.print_exc(file=self.ostream)
        info('\nUnfortunately, your original traceback can not be constructed.\n')
        return None**

But the next operation with return value that it is called len() in IPython.core.ultratb.find_recursion, and this causes an exception and IPython crash.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

Hi. I think the issue is still existing. On my side I manage to reproduce the issue with click library. The minimal code snippet is below.

import click

@click.command()
@click.option('--nb_files', type=int, help='number of files to load')
def execute_job(nb_files):
    print('hello world', nb_files)
    return nb_files

if __name__ == '__main__':
    execute_job()

Then executed in IPython with the following argugments:

--nb_files 20

I encounter the issue with IPython version 7.22.0 , on Databricks platform using a “Python” job (actions with them are also ongoing).

Should we create a different issue for this one in case this is specific to click? Let me know. Thanks.

It seems that click is calling a sys.exit(0) after your app has finished and ipython mistakes this as an error. We solved the problem by wrapping our application in a try except block:

try:
    app()
except SystemExit as e:
    if e.code != 0:
        raise

see also this Stackoverflow post: https://stackoverflow.com/questions/52740295/how-to-not-exit-a-click-cli

Same issue here with IPython version 7.27.0 on Databricks, are there any news on that?