Skip to content
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

Idle: stop depending on console output #62518

Open
terryjreedy opened this issue Jun 27, 2013 · 4 comments
Open

Idle: stop depending on console output #62518

terryjreedy opened this issue Jun 27, 2013 · 4 comments
Assignees
Labels
topic-IDLE type-bug An unexpected behavior, bug, or error

Comments

@terryjreedy
Copy link
Member

BPO 18318
Nosy @terryjreedy, @ned-deily, @serwy, @roseman

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/terryjreedy'
closed_at = None
created_at = <Date 2013-06-27.22:43:29.439>
labels = ['expert-IDLE', 'type-bug', '3.10']
title = 'Idle: stop depending on console output'
updated_at = <Date 2020-06-07.23:27:02.960>
user = 'https://github.com/terryjreedy'

bugs.python.org fields:

activity = <Date 2020-06-07.23:27:02.960>
actor = 'terry.reedy'
assignee = 'terry.reedy'
closed = False
closed_date = None
closer = None
components = ['IDLE']
creation = <Date 2013-06-27.22:43:29.439>
creator = 'terry.reedy'
dependencies = []
files = []
hgrepos = []
issue_num = 18318
keywords = []
message_count = 3.0
messages = ['191966', '192087', '192094']
nosy_count = 5.0
nosy_names = ['terry.reedy', 'ggenellina', 'ned.deily', 'roger.serwy', 'markroseman']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'test needed'
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue18318'
versions = ['Python 3.10']

@terryjreedy
Copy link
Member Author

terryjreedy commented Jun 27, 2013

It appears that Idle was originally written to run on *nix after being launched from a command-line console. Messages related to Idle code (warnings and exceptions) are sent back to the console, while messages related to user code go to the shell window. This makes Idle a hybrid text/gui application.

Later, Idle was ported to run on Windows with the pythonw.exe no-console binary. When it is started normally for Windows, from anything but a console, there is no console. This has caused problems when Idle tries to write to the non-existent console. (I do not know the situation on modern Mac and *nix.) (Even when a console does exist, it will usually get buried and messages may not be seen.)

Example: The warning system, monkey patched in both PyShell.py and run.py and documented in the former. (Edited quote from 3.3.)

# Override warnings module to write to warning_stream.
# Initialize to send IDLE internal warnings to the console.
# ScriptBinding.check_syntax() will temporarily redirect the stream
# to the shell window to display warnings when checking user's code.
warning_stream = sys.__stderr__  # Typically None, at least on Windows.
def idle_showwarning(...
    ...
    if file is None:
        file = warning_stream  # Which may itself be None!!!
    try:
        file.write(...  # AttributeError when file is still None
    except OSError:
        pass  # if file (probably __stderr__) is invalid, skip warning.

The patch for #62281 also catches AttributeError as a bandage.

[EDIT 2023 May 6: None.write AttributeError is now also caught. An alternative, used in config.py, is print(..., file=sys....).]

Issue goal: make Idle a true gui app by removing the dependence on a console, which may not exist.

Proposed method: re-factor Idle startup to try to import tkinter first, rather than last.

If this import fails, inform user with console message and/or the os-specific means to gui apps to tell users 'I cannot start because ...'. I know this exists on Windows because I have seen such messages. I presume same is true on other systems.

If this import succeeds, setup traceback and warnings hooks to send internal messages to a gui messagebox rather than (or possibly in addition to) a console that may or may not be present. Or send the messages to the Shell window, but marked somehow as internal. The warnings hook might be used after importing non-Idle modules but before importing Idle modules, so startup is not bogged down on debug builds by DeprecationWarnings from non-Idle modules

To be a good citizen for testing, all custom hooks should be undone before the PyShell import finishes and before PyShell.main exits (same for run.py).

@terryjreedy terryjreedy added the type-bug An unexpected behavior, bug, or error label Jun 27, 2013
@serwy
Copy link
Mannequin

serwy mannequin commented Jun 30, 2013

This looks similar to #57791 with the patch to redirect console writes to a GUI text box.

@terryjreedy
Copy link
Member Author

terryjreedy commented Jun 30, 2013

The proposal here is to flip the roles of text console and graphics gui, rather than to indefinitely bandage the current roles. I would want that even with the patch for #57791 applied (which I hope can be done soon).

@terryjreedy terryjreedy self-assigned this Jun 19, 2017
@terryjreedy terryjreedy added the 3.7 (EOL) end of life label Jun 29, 2017
@terryjreedy terryjreedy added 3.10 only security fixes and removed 3.7 (EOL) end of life labels Jun 7, 2020
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@arhadthedev
Copy link
Member

Later, Idle was ported to run on Windows with the pythonw.exe no-console binary. When it is started normally for Windows, from anything but a console, there is no console. This has caused problems when Idle tries to write to the non-existent console.

This point will be fixed by gh-101802.

I agree with the rest, though.

@terryjreedy terryjreedy removed the 3.10 only security fixes label May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-IDLE type-bug An unexpected behavior, bug, or error
Projects
Status: No status
Development

No branches or pull requests

2 participants