Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

code.interact() will exit the whole process when given exit() or quit() #102895

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
@gaogaotiantian

Description

@gaogaotiantian

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 commandexit() (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 catchingSystemExit 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 theexit andquit inbuiltins in the interactive shell, and switch back after. This will also makepdb happier.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp