Skip to content

gh-119517: Fix several issues when pasting lot of text in the REPL #120234

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

Closed
wants to merge 3 commits into from

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Jun 7, 2024

  • Restore signal handlers for SIGINT and SIGSTOP (Ctrl-C and Ctrl-Z)
  • Ensure that signals are processed as soon as possible by making
    reads more efficient.
  • Protect against invalid state in internal REPL functions when
    interrumpted.
  • Do not show extraneous newlines above the scroll buffer when pasting
    text in the REPL

Signed-off-by: Pablo Galindo [email protected]

* Restore signal handlers for SIGINT and SIGSTOP (Ctrl-C and Ctrl-Z)
* Ensure that signals are processed as soon as possible by making
  reads more efficient.
* Protect against invalid state in internal REPL functions when
  interrumpted.
* Do not show extraneous newlines above the scroll buffer when pasting
  text in the REPL

Signed-off-by: Pablo Galindo <[email protected]>
@pablogsal
Copy link
Member Author

@treyhunner can you check this PR? (Both the issues and the performance of pasting)

Signed-off-by: Pablo Galindo <[email protected]>
@treyhunner
Copy link
Member

This is certainly an improvement, both in Ctrl-C working and in the extraneously newlines not appearing.

Restore signal handlers for SIGINT and SIGSTOP (Ctrl-C and Ctrl-Z)

Ctrl-C works pretty much the way I would expect now.

When pasting a document that would have taken ~20 seconds to fully paste, I hit Ctrl-C after a few seconds of the terminal hanging. This continued the pasting the rest of the lines in the document, which resulted in syntax errors. But that noise was just a minor annoyance.

It would be nice to see the paste operation stop entirely when Ctrl-C is pressed (to avoid the syntax errors) but I'm fine with this current behavior for now.

I expect that this will mostly be useful when my students or I accidentally paste the wrong text and then try to hit Ctrl-C to escape.
This current behavior works for that use case.

Do not show extraneous newlines above the scroll buffer when pasting text in the REPL

When my REPL was in this state, I pasted 604 lines of text:

>>> x = 4
>>> y = """

Then when I scrolled up I saw only a couple lines above my current terminal screen (regardless of screen size this seems to be the case).
The first line was slightly confusing initially:

>>> x = 4
... have endeavoured to discover what quality it is which he possesses that

It looks like the y = """ line disappeared. That was confusing at first, as I initially thought x = 4 had replaced that line somehow.

This behavior does seem like an improvement over the many blank lines that were shown before. It would be nice to see the full history, like in the old REPL. But I can live with seeing a "tail" of the pasted text up to the current screen height instead.

Thank you!

@pablogsal
Copy link
Member Author

pablogsal commented Jun 7, 2024

It would be nice to see the full history, like in the old REPL.

One thing I noticed is that IPython does the same as we are doing here: you will not be able to see the full history (try it out) so this solution si also widespread.

@pablogsal
Copy link
Member Author

It would be nice to see the paste operation stop entirely when Ctrl-C is pressed (to avoid the syntax errors) but I'm fine with this current behavior for now.

Maybe we can look into that afterwards

@pablogsal
Copy link
Member Author

When pasting a document that would have taken ~20 seconds to fully paste

Now pasting its much faster as well. I can paste the full Frankenstein in almost the same time as the old REPL.

@pablogsal
Copy link
Member Author

pablogsal commented Jun 7, 2024

Then when I scrolled up I saw only a couple lines above my current terminal screen (regardless of screen size this seems to be the case).

@treyhunner I tried this and Ipython also does something weird as well so I am not too concerned:
Screenshot 2024-06-07 at 18 50 54
and then paste and scroll:
Screenshot 2024-06-07 at 18 51 16

@treyhunner
Copy link
Member

treyhunner commented Jun 7, 2024

One thing I noticed is that IPython does the same as we are doing here: you will not be able to see the full history (try it out) so this solution si also widespread.

I'm able to reproduce this same behavior in both IPython and ptpython. I've never noticed this behavior while using IPython over the years, so this must be less important to me than I thought.

Now pasting its much faster as well. I can paste the full Frankenstein in almost the same time as the old REPL.

I just reinstalled Python from the latest version of this branch (via https://github.com/pablogsal/cpython/archive/paste.tar.gz) and pasting the entire text of Frankenstein still seems to take ~20 seconds.

I'm testing on testing on Ubuntu 22.04.4 with a fairly standard system configuration.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Co-authored-by: Nikita Sobolev <[email protected]>
@pablogsal
Copy link
Member Author

Closing in favor of #120253

@pablogsal pablogsal closed this Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants