-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] rich crashes ipython when printing a traceback after due to StopIteration
error
#2821
Comments
I think this is the same underlying issue as #2800 |
exact same thing is happening to me, what is the suggested fix for this? this is breaking our prod build and we need an urgent fix, please let us know or we'll have to move off rich, thanks im using django-rich and here's a stack trace
|
I hope we solved your problem. If you like using Rich, you might also enjoy Textual |
thanks, confirming it works again on latest version!! |
Describe the bug
Using
%load_ext rich
in python, printing a traceback will sometimes cause ipython to crash with an errorRuntimeError: generator raised StopIteration
It's possible this is related to #2781, and maybe others with strange crashes/hanging?
Example code
(sorry i couldn't find one without pydantic, this was just the quickest/smallest thing related to what I was really doing)
saved into
testrich.py
then in ipython
(mapping) staniewi:data$ ipython Python 3.10.9 | packaged by conda-forge | (main, Feb 2 2023, 20:26:08) [Clang 14.0.6 ] Type 'copyright', 'credits' or 'license' for more information IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: import testrich In [2]: testrich.Dummy() --------------------------------------------------------------------------- ValueError Traceback (most recent call last) Input In [2], in <cell line: 1>() ----> 1 testrich.Dummy() File ~/repos/sweets/testrich.py:7, in Dummy.__init__(self, **data) 5 def __init__(self, **data): 6 super().__init__(**data) ----> 7 self.new_attribute = "this should error due to pydantic" File ~/miniconda3/envs/mapping/lib/python3.10/site-packages/pydantic/main.py:358, in pydantic.main.BaseModel.__setattr__() ValueError: "Dummy" object has no field "new_attribute"
that's whats supposed to be printed. Here's with rich:
In [3]: %load_ext rich In [4]: testrich.Dummy() Traceback (most recent call last): File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3398, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-4-ecd4ba56830a>", line 1, in <cell line: 1> testrich.Dummy() File "/Users/staniewi/repos/sweets/testrich.py", line 7, in __init__ self.new_attribute = "this should error due to pydantic" File "pydantic/main.py", line 358, in pydantic.main.BaseModel.__setattr__ ValueError: "Dummy" object has no field "new_attribute" During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/syntax.py", line 497, in tokens_to_spans _token_type, token = next(tokens) StopIteration The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3338, in run_ast_nodes if await self.run_code(code, result, async_=asy): File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3420, in run_code self.showtraceback(running_compiled_code=True) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/traceback.py", line 130, in ipy_show_traceback default_showtraceback(*args, **kwargs) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 2004, in showtraceback self._showtraceback(etype, value, stb) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/traceback.py", line 151, in ipy_display_traceback excepthook(exc_tuple[0], exc_tuple[1], tb) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/traceback.py", line 102, in excepthook traceback_console.print( File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1694, in print extend(render(renderable, render_options)) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1330, in render yield from self.render(render_output, _options) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1326, in render for render_output in iter_render: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/constrain.py", line 29, in __rich_console__ yield from console.render(self.renderable, child_options) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1326, in render for render_output in iter_render: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/panel.py", line 220, in __rich_console__ lines = console.render_lines(renderable, child_options, style=style) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1366, in render_lines lines = list( File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/segment.py", line 292, in split_and_crop_lines for segment in segments: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1326, in render for render_output in iter_render: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/padding.py", line 97, in __rich_console__ lines = console.render_lines( File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1366, in render_lines lines = list( File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/segment.py", line 292, in split_and_crop_lines for segment in segments: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1330, in render yield from self.render(render_output, _options) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1326, in render for render_output in iter_render: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/syntax.py", line 609, in __rich_console__ segments = Segments(self._get_syntax(console, options)) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/segment.py", line 668, in __init__ self.segments = list(segments) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/syntax.py", line 637, in _get_syntax text = self.highlight(processed_code, self.line_range) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/syntax.py", line 509, in highlight text.append_tokens(tokens_to_spans()) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/text.py", line 995, in append_tokens for content, style in tokens: RuntimeError: generator raised StopIteration During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/syntax.py", line 497, in tokens_to_spans _token_type, token = next(tokens) StopIteration The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 2936, in _run_cell return runner(coro) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/IPython/core/async_helpers.py", line 129, in _pseudo_sync_runner coro.send(None) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3135, in run_cell_async has_raised = await self.run_ast_nodes(code_ast.body, cell_name, File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3357, in run_ast_nodes self.showtraceback() File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/traceback.py", line 130, in ipy_show_traceback default_showtraceback(*args, **kwargs) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 2004, in showtraceback self._showtraceback(etype, value, stb) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/traceback.py", line 151, in ipy_display_traceback excepthook(exc_tuple[0], exc_tuple[1], tb) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/traceback.py", line 102, in excepthook traceback_console.print( File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1694, in print extend(render(renderable, render_options)) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1330, in render yield from self.render(render_output, _options) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1326, in render for render_output in iter_render: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/constrain.py", line 29, in __rich_console__ yield from console.render(self.renderable, child_options) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1326, in render for render_output in iter_render: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/panel.py", line 220, in __rich_console__ lines = console.render_lines(renderable, child_options, style=style) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1366, in render_lines lines = list( File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/segment.py", line 292, in split_and_crop_lines for segment in segments: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1326, in render for render_output in iter_render: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/padding.py", line 97, in __rich_console__ lines = console.render_lines( File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1366, in render_lines lines = list( File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/segment.py", line 292, in split_and_crop_lines for segment in segments: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1330, in render yield from self.render(render_output, _options) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1326, in render for render_output in iter_render: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/syntax.py", line 609, in __rich_console__ segments = Segments(self._get_syntax(console, options)) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/segment.py", line 668, in __init__ self.segments = list(segments) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/syntax.py", line 637, in _get_syntax text = self.highlight(processed_code, self.line_range) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/syntax.py", line 509, in highlight text.append_tokens(tokens_to_spans()) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/text.py", line 995, in append_tokens for content, style in tokens: RuntimeError: generator raised StopIteration During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/syntax.py", line 497, in tokens_to_spans _token_type, token = next(tokens) StopIteration The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/Users/staniewi/miniconda3/envs/mapping/bin/ipython", line 11, in <module> sys.exit(start_ipython()) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/IPython/__init__.py", line 124, in start_ipython return launch_new_instance(argv=argv, **kwargs) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/traitlets/config/application.py", line 976, in launch_instance app.start() File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/IPython/terminal/ipapp.py", line 318, in start self.shell.mainloop() File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 680, in mainloop self.interact() File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 673, in interact self.run_cell(code, store_history=True) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 2881, in run_cell result = self._run_cell( File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 2943, in _run_cell self.showtraceback(running_compiled_code=True) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/traceback.py", line 130, in ipy_show_traceback default_showtraceback(*args, **kwargs) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 2004, in showtraceback self._showtraceback(etype, value, stb) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/traceback.py", line 151, in ipy_display_traceback excepthook(exc_tuple[0], exc_tuple[1], tb) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/traceback.py", line 102, in excepthook traceback_console.print( File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1694, in print extend(render(renderable, render_options)) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1330, in render yield from self.render(render_output, _options) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1326, in render for render_output in iter_render: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/constrain.py", line 29, in __rich_console__ yield from console.render(self.renderable, child_options) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1326, in render for render_output in iter_render: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/panel.py", line 220, in __rich_console__ lines = console.render_lines(renderable, child_options, style=style) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1366, in render_lines lines = list( File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/segment.py", line 292, in split_and_crop_lines for segment in segments: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1326, in render for render_output in iter_render: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/padding.py", line 97, in __rich_console__ lines = console.render_lines( File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1366, in render_lines lines = list( File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/segment.py", line 292, in split_and_crop_lines for segment in segments: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1330, in render yield from self.render(render_output, _options) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/console.py", line 1326, in render for render_output in iter_render: File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/syntax.py", line 609, in __rich_console__ segments = Segments(self._get_syntax(console, options)) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/segment.py", line 668, in __init__ self.segments = list(segments) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/syntax.py", line 637, in _get_syntax text = self.highlight(processed_code, self.line_range) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/syntax.py", line 509, in highlight text.append_tokens(tokens_to_spans()) File "/Users/staniewi/miniconda3/envs/mapping/lib/python3.10/site-packages/rich/text.py", line 995, in append_tokens for content, style in tokens: RuntimeError: generator raised StopIteration If you suspect this is an IPython 8.4.0 bug, please report it at: https://github.com/ipython/ipython/issues or send an email to the mailing list at ipython-dev@python.org You can print a more detailed traceback right now with "%tb", or use "%debug" to interactively debug it. Extra-detailed tracebacks for bug-reporting purposes can be enabled via: %config Application.verbose_crash=True (mapping) staniewi:data$
Platform
Click to expand
What platform (Win/Linux/Mac) are you running on? What terminal software are you using?
Mac arm M1
The text was updated successfully, but these errors were encountered: