Skip to content

Bpython breaks when printing large data structures #1037

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

Open
truck-iguana opened this issue Apr 27, 2025 · 1 comment
Open

Bpython breaks when printing large data structures #1037

truck-iguana opened this issue Apr 27, 2025 · 1 comment

Comments

@truck-iguana
Copy link

truck-iguana commented Apr 27, 2025

I'm surprised I haven't found another issue raised about this, or maybe I missed it.

This is a frequent problem for me. If I am in the bpython shell and try to print out a large data structure, the shell crashes and it is frustrating. The big selling point of entering the shell is to be interactive with the environment, which means sometimes I want to display my data.

In this specific instance, I have a nested list structure. that looks like this

[
  ["string","string","string"..],
  ["string","string","string"..],
  ...
]

When I do a bit of debugging

sum([len(y) for x in my_nested_list[:50] for y in x])

I get 36453. So this means the excerpt I'm going to "print" to my screen has 36,453 bytes of characters in it, spread across 30 nested lists.

In bpython shell, when I simply do

>>> my_nested_list[:50]

The shell crashes:

Traceback (most recent call last):
  File "/path/to/venv/bin/bpython", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/path/to/venv/lib64/python3.13/site-packages/bpython/curtsies.py", line 245, in main
    repl.mainloop(True, paste)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/path/to/venv/lib64/python3.13/site-packages/bpython/curtsies.py", line 178, in mainloop
    self.process_event_and_paint(e)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
  File "/path/to/venv/lib64/python3.13/site-packages/bpython/curtsies.py", line 149, in process_event_and_paint
    scrolled = self.window.render_to_terminal(array, cursor_pos)
  File "/path/to/venv/lib64/python3.13/site-packages/curtsies/window.py", line 491, in render_to_terminal
    self.scroll_down()
    ~~~~~~~~~~~~~~~~^^
  File "/path/to/venv/lib64/python3.13/site-packages/curtsies/window.py", line 56, in scroll_down
    with self.t.location(x=0, y=1000000):
         ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.13/contextlib.py", line 141, in __enter__
    return next(self.gen)
  File "/path/to/venv/lib64/python3.13/site-packages/blessed/terminal.py", line 594, in location
    self.stream.flush()
    ~~~~~~~~~~~~~~~~~^^
  File "/path/to/venv/lib64/python3.13/site-packages/bpython/curtsiesfrontend/repl.py", line 623, in sigwinch_handler
    cursor_dy = self.get_cursor_vertical_diff()
  File "/path/to/venv/lib64/python3.13/site-packages/bpython/curtsies.py", line 118, in get_cursor_vertical_diff
    return self.window.get_cursor_vertical_diff()
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/path/to/venv/lib64/python3.13/site-packages/curtsies/window.py", line 398, in get_cursor_vertical_diff
    cursor_dy += self._get_cursor_vertical_diff_once()
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/path/to/venv/lib64/python3.13/site-packages/curtsies/window.py", line 406, in _get_cursor_vertical_diff_once
    row, col = self.get_cursor_position()
               ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/path/to/venv/lib64/python3.13/site-packages/curtsies/window.py", line 315, in get_cursor_position
    return self.t.get_location()
           ~~~~~~~~~~~~~~~~~~~^^
  File "/path/to/venv/lib64/python3.13/site-packages/blessed/terminal.py", line 651, in get_location
    match = self._query_response(
        self.u7 or u'\x1b[6n', self.caps['cursor_report'].re_compiled, timeout
    )
  File "/path/to/venv/lib64/python3.13/site-packages/blessed/terminal.py", line 528, in _query_response
    self.stream.flush()
    ~~~~~~~~~~~~~~~~~^^
RuntimeError: reentrant call inside <_io.BufferedWriter name='<stdout>'>
@truck-iguana
Copy link
Author

Found another issue about this bpython/curtsies/issues/173

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant