-
-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
code.interact() will exit the whole process when given exit() or quit() #102895
Comments
We would only consider this a bug if behaviour contradicts the documentation. Is this the case? |
You want to change the behavior of a library that's been like this since 1998. It's not clear to me that making Even if we agree to introduce this behavior, Therefore, any additional functionality would have to live in the class as a non-default option. |
I understood this will break the backward compatibility. I considered this as a bug mainly because - when you type I hit this issue when I was trying to test But, now that we are on that topic, the actual issue evolves - when the users are using |
I think we can provide user an option to enable this feature? Keep all the default behavior as before, but add an optional |
I made a modification to the implementation. Now this feature will be hidden behind a new option for If this is something we can do, I'll work on the documetation for the explanation. |
…rom terminating the whole process (GH-102896)
…it() from terminating the whole process (pythonGH-102896)
…it() from terminating the whole process (pythonGH-102896)
code.interact()
is provided as a method to embed an interactive shell in arbitrary python code. It was used inpdb
forinteract
command.However, when the user needs to exit, they probably will use a very familiar command
exit()
(orquit()
), then they'll realize that the whole process is terminated. In most of the cases, that's not the expected bahavior. The user probably just wants to exit the interpreter and go back to the original code.Ctrl+D(Ctrl+Z then enter) works as expected because there's logic to handle that specifically.
Simply catching
SystemExit
won't work becausebuiltins.exit()
andbuiltins.quit()
(if provided) will also closesys.stdin
(weird behavior to me) and it's not trivial to reopenstdin
.To provide a more reasonable and unified behavior, we can replace the
exit
andquit
inbuiltins
in the interactive shell, and switch back after. This will also makepdb
happier.Linked PRs
The text was updated successfully, but these errors were encountered: