-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Error exiting the new REPL with Ctrl+Z on Windows #119896
Comments
This post is just an FYI for the developers of the new REPL. On the subject of control characters, I see that Ctrl+C is mapped to the "interrupt" command. In the Currently, it appears that this isn't an issue in practice, since the REPL doesn't clear the |
Full output:
The error comes from the |
A meetoo probably isn't of any help, but I was also surprised to run into this harmless-but-alarming-looking traceback on exiting. Definitely, the expectation based on long-time previous behavior is that |
This is still broken as of 3.13.0b4, the final beta. It's going to be pretty bad look if it goes out the door like this... |
Would something like this work? diff --git a/Lib/_pyrepl/reader.py b/Lib/_pyrepl/reader.py
index 8b282a382d3..bbedcf50056 100644
--- a/Lib/_pyrepl/reader.py
+++ b/Lib/_pyrepl/reader.py
@@ -23,6 +23,7 @@
from contextlib import contextmanager
from dataclasses import dataclass, field, fields
+import sys
import unicodedata
from _colorize import can_colorize, ANSIColors # type: ignore[import-not-found]
@@ -110,7 +111,7 @@ def make_default_commands() -> dict[CommandName, type[Command]]:
(r"\C-w", "unix-word-rubout"),
(r"\C-x\C-u", "upcase-region"),
(r"\C-y", "yank"),
- (r"\C-z", "suspend"),
+ (r"\C-z", "interrupt" if sys.platform.startswith("win32") else "suspend"),
(r"\M-b", "backward-word"),
(r"\M-c", "capitalize-word"),
(r"\M-d", "kill-word"), |
I now believe the best solution is to check for Windows in the suspend command, like so: diff --git a/Lib/_pyrepl/commands.py b/Lib/_pyrepl/commands.py
index c3fce91013b..de5e02356dd 100644
--- a/Lib/_pyrepl/commands.py
+++ b/Lib/_pyrepl/commands.py
@@ -21,6 +21,7 @@
from __future__ import annotations
import os
+import sys
# Categories of actions:
# killing
@@ -229,10 +230,21 @@ def do(self) -> None:
class suspend(Command):
def do(self) -> None:
- import signal
-
r = self.reader
p = r.pos
+ b = r.buffer
+ if sys.platform.startswith("win32"):
+ if (
+ p == 0
+ and len(b) == 0
+ and self.event[-1] == "\032"
+ ):
+ r.update_screen()
+ r.console.finish()
+ raise EOFError
+ else:
+ return
+ import signal
r.console.finish()
os.kill(os.getpid(), signal.SIGSTOP)
## this should probably be done However, that still changes the behavior compared to the basic REPL, because in it users have to press Ctrl+Z then Enter, while in PyREPL just Ctrl+Z will exit. |
The former seemed to work when I hacked in (modulo that it reported Personally, not too worried if ^Z quits immediately, since that's what happens on POSIX platforms for ^D. But yes, it's slightly different from the original-REPL behavior. |
…onGH-122217) (cherry picked from commit d1a1bca) Co-authored-by: Dino Viehland <[email protected]>
Triage: closing because the linked PR is merged, please re-open if still needed. |
Bug report
Bug description:
With the new REPL implementation on Windows, I'm getting an error from code that mistakenly tries to suspend the current process via
os.kill(os.getpid(), signal.SIGSTOP)
when exiting via Ctrl+Z, Enter. This raises the followingAttributeError
:This is due to Ctrl+Z getting mapped to the "suspend" command. This key sequence has always been supported for exiting the REPL on Windows. It's also supported when reading from
io._WindowsConsoleIO
console-input files. Anything after Ctrl+Z at the start of a line gets ignored, yielding an empty read.Note that the kernel on Windows has no support for POSIX signals. There's just a basic emulation of a few signals in the C runtime library. There's no support for
SIGSTOP
. It could be emulated, but it's not, and the GUI task manager hasn't implemented support for suspending and resuming processes. Thus on Windows you could just map Ctrl+Z to the "delete" command, and update thedelete
class to also exit the REPL if the raw event character is"\x1a"
.CPython versions tested on:
CPython main branch
Operating systems tested on:
Windows
Linked PRs
The text was updated successfully, but these errors were encountered: