GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-36829: Add _PyErr_WriteUnraisableMsg() by vstinner · Pull Request #13488 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented May 22, 2019 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • sys.unraisablehook: add 'err_msg' field to UnraisableHookArgs.
  • Use _PyErr_WriteUnraisableMsg() in _ctypes _DictRemover_call()
    and gc delete_garbage().

https://bugs.python.org/issue36829

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
vstinner requested a review from serhiy-storchaka May 22, 2019 10:10
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label May 22, 2019
@bedevere-bot bedevere-bot added the awaiting core review label May 22, 2019
@vstinner vstinner added the skip news label May 22, 2019
This was referenced May 22, 2019
bpo-36829: Add sys.unraisablehook() #13187
Merged
bpo-36829: Add test.support.catch_unraisable_exception() #13490
Merged
@vstinner

vstinner commented May 22, 2019

Copy link
Copy Markdown
Member Author

Interesting case: _PyErr_WarnUnawaitedCoroutine():

        if (PyErr_WarnFormat(PyExc_RuntimeWarning, 1,
                             "coroutine '%.50S' was never awaited",
                             ((PyCoroObject *)coro)->cr_qualname) < 0)
        {
            PyErr_WriteUnraisable(coro);
        }

The unraisable exception is logged with default "Exception ignored in: ..." message. Should we use a customized error message here?

In my PR #13490, I have to catch stderr and sys.unraisablehook to catch the warning and the unraisable exception in test_coroutines.test_unawaited_warning_when_module_broken():
https://github.com/python/cpython/pull/13490/files

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented May 22, 2019

Copy link
Copy Markdown
Member Author

@graingert @pablogsal @serhiy-storchaka: Would you mind to review this PR? I don't recall who asked me to allow to specify a custom error message :-)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka
serhiy-storchaka reviewed May 22, 2019
View reviewed changes
Comment thread Include/pyerrors.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/gcmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/errors.c Outdated

@serhiy-storchaka serhiy-storchaka May 22, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can avoid duplication of the code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner May 24, 2019

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to have a single PyFile_WriteString(":\n", file) call in this code path, rather than trying to factorize the code too much, to reduce the risk of failure in the hook.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner

vstinner commented May 24, 2019

Copy link
Copy Markdown
Member Author

I rebased my PR and merged conflicts.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
bpo-36829: Add _PyErr_WriteUnraisableMsg()
a56e060
* sys.unraisablehook: add 'err_msg' field to UnraisableHookArgs.
* Use _PyErr_WriteUnraisableMsg() in _ctypes _DictRemover_call()
  and gc delete_garbage().
@vstinner

vstinner commented May 24, 2019

Copy link
Copy Markdown
Member Author

@serhiy-storchaka: Would you mind to review the update PR?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka
serhiy-storchaka reviewed May 24, 2019
View reviewed changes
Comment thread Doc/library/sys.rst
exceptions are handled.

The default hook formats *err_msg* and *object* as:
``f'{err_msg}: {object!r}'``; use "Exception ignored in" error message

@serhiy-storchaka serhiy-storchaka May 24, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
``f'{err_msg}: {object!r}'``; use "Exception ignored in" error message
``f'Exception ignored {err_msg}: {object!r}'``; use "Exception ignored in" error message

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner May 24, 2019

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really logs f'{err_msg}: {object!r}'. _PyErr_WriteUnraisableMsg("xxx") sets err_msg to "Exception ignored xxx".

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
pablogsal
pablogsal reviewed May 24, 2019
View reviewed changes
Comment thread Python/errors.c
}

if (err_msg_str != NULL) {
err_msg = PyUnicode_FromFormat("Exception ignored %s", err_msg_str);

@pablogsal pablogsal May 24, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hummm, why don't allowing the caller to control the full error message? (Instead of prepending "Exception ignored")

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner May 24, 2019

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@serhiy-storchaka asked me to do so :-) And when I started a draft change to convert existing PyErr_WriteUnraisable() to _PyErr_WriteUnraisableMsg(), I always started error messages with "Exception ignored ".

The hook allows to control the full error message. Only proposed _PyErr_WriteUnraisableMsg() enfoce "Exception ignored " prefix. We might add a new function later if needed to let control the full error message.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner May 26, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, making "Exception ignored " prefix part of the API should reduce the size of the Python executable binary since constant strings are shorter (remove common "Exception ignored " prefix ;-)).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner

vstinner commented May 26, 2019

Copy link
Copy Markdown
Member Author

@serhiy-storchaka @pablogsal: So do you agree each other on "Exception ignored" prefix? :-)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal

pablogsal commented May 26, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

So do you agree each other on "Exception ignored" prefix? :-)

Yup, I'm happy with it :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner merged commit 71c52e3 into python:master May 27, 2019
@bedevere-bot bedevere-bot removed the awaiting core review label May 27, 2019
@vstinner
vstinner deleted the unraisable_msg branch May 27, 2019 06:57
DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
@vstinner @DinoV
bpo-36829: Add _PyErr_WriteUnraisableMsg() (pythonGH-13488)
c9d43b2
* sys.unraisablehook: add 'err_msg' field to UnraisableHookArgs.
* Use _PyErr_WriteUnraisableMsg() in _ctypes _DictRemover_call()
  and gc delete_garbage().
@encukou encukou mentioned this pull request Aug 2, 2024
sys.flags.gil should be a "sequence" attribute OR stop adding to the sequence #122575
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@pablogsal pablogsal pablogsal left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@vstinner @pablogsal @serhiy-storchaka @the-knights-who-say-ni @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.