Skip to content

IDLE: no Shell menu item in single-process mode #112936

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
terryjreedy opened this issue Dec 10, 2023 · 8 comments
Closed

IDLE: no Shell menu item in single-process mode #112936

terryjreedy opened this issue Dec 10, 2023 · 8 comments
Assignees
Labels
3.12 only security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-IDLE type-bug An unexpected behavior, bug, or error

Comments

@terryjreedy
Copy link
Member

terryjreedy commented Dec 10, 2023

Start IDLE with python -m idlelib -n and the Shell menu is missing 'Shell'.

-n mode is semi-deprecated, but this is egregious and should be easily fixed.

Linked PRs

@MidnightCrowing
Copy link

Hello,
I’m planning to work on fixing this issue, and I noticed this part of the code:

        if use_subprocess:
            ms = self.menu_specs
            if ms[2][0] != "shell":
                ms.insert(2, ("shell", "She_ll"))

Would it be feasible to simply remove the if use_subprocess: condition? I'm unsure if this change could cause other issues and would appreciate your input.

Thank you!

@Xiaokang2022
Copy link
Contributor

@terryjreedy, I dug through past code to find the cause of the issue and tried to fix it, and I'll create a PR in a while.

@Xiaokang2022
Copy link
Contributor

Xiaokang2022 commented Nov 8, 2024

First of all, I found out that this issue was artificially introduced, which was brought up by kbkaiser in a commit 21 years ago (8f570a7):

image

And the changes are as follows:

  1. Add a command line switch to run without the subprocess
  2. Remove the shell menu and associated bindings when running
    without the subprocess.
  3. Update the IDLE Help and usage text.
  4. Update display_port_binding_error to suggest using -n

The key lies in the second point. And it's IMPORTANT to note that at that time there were only two options for the menu "shell":

image

After testing, these two functions are not available when using the parameter "-n" and cause some errors. So I'm guessing that's why kbkaiser disabled the menu "shell" at that time.

But from the image above, we can clearly see that more features have been added to the menu "shell" since then. After testing, the rest of the functions work correctly when using the parameter "-n".

So I think the appropriate fix would be to restore the menu "shell" while disabling the two previously mentioned options that can't be used when using the "-n" parameter.

The final effect is as follows:

image

Maybe there is some problem with my idea, if there is, please help me point it out, thanks!

@Xiaokang2022
Copy link
Contributor

Xiaokang2022 commented Nov 8, 2024

The basic idea is like that, but I'm not very clear as to why those two features cause errors in single-process mode. Perhaps we should address this issue in detail in the documentation?

@picnixz picnixz added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error 3.12 only security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Nov 9, 2024
@serhiy-storchaka
Copy link
Member

In single process mode, the GUI and the user program are ran in the same process. What are you going to restart?

@Xiaokang2022
Copy link
Contributor

In single process mode, the GUI and the user program are ran in the same process. What are you going to restart?

Yes! It makes so much sense, how I didn't think of this question!

miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 2, 2025
…ythonGH-126598)

(cherry picked from commit 7e7e49b)

Co-authored-by: Zhikang Yan <2951256653@qq.com>
serhiy-storchaka pushed a commit that referenced this issue May 2, 2025
…GH-126598) (GH-133310)

(cherry picked from commit 7e7e49b)

Co-authored-by: Zhikang Yan <2951256653@qq.com>
@terryjreedy
Copy link
Member Author

Thank you all for the research, fix, and merge. I somehow missed the posting of the PR. I added 2 draft follow-up issues to the Restart topic of the IDLE issues Project page.

  1. View Restart should consider the initial start a restart, making it applicable in -n mode.
  2. The documented purpose of Restart is to 'clean the environment'. This is applicable and I believe easily done in -n mode. Restarting a dead or stuck subprocess as a super-interrupt to regain control when ^-C fails would remain normal-mode only.

@serhiy-storchaka
Copy link
Member

The user code shares the environment (e.g. imported modules, sys settings, opened file descriptors, Tkinter widgets) with IDLE. It cannot be cleaned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 only security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-IDLE type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

5 participants