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

bpo-36829: Add _PyErr_WriteUnraisableMsg()#13488

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 1 commit intopython:masterfromvstinner:unraisable_msg
May 27, 2019
Merged

bpo-36829: Add _PyErr_WriteUnraisableMsg()#13488

vstinner merged 1 commit intopython:masterfromvstinner:unraisable_msg
May 27, 2019

Conversation

vstinner
Copy link
Member

@vstinnervstinner commentedMay 22, 2019
edited by bedevere-bot
Loading

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

https://bugs.python.org/issue36829

@vstinner
Copy link
MemberAuthor

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 stderrand 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

@vstinner
Copy link
MemberAuthor

@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 :-)

@@ -1040,6 +1053,14 @@ write_unraisable_exc_file(PyObject *exc_type, PyObject *exc_value,
return -1;
}
}
else if (err_msg != NULL && err_msg != Py_None) {

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.

Copy link
MemberAuthor

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.

@vstinner
Copy link
MemberAuthor

I rebased my PR and merged conflicts.

* sys.unraisablehook: add 'err_msg' field to UnraisableHookArgs.* Use _PyErr_WriteUnraisableMsg() in _ctypes _DictRemover_call()  and gc delete_garbage().
@vstinner
Copy link
MemberAuthor

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

* *object*: Object causing the exception, can be ``None``.

:func:`sys.unraisablehook` can be overridden to control how unraisable
exceptions are handled.

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

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

Copy link
MemberAuthor

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".

@@ -1322,13 +1351,20 @@ PyErr_WriteUnraisable(PyObject *obj)
}
}

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

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")

Copy link
MemberAuthor

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.

Copy link
MemberAuthor

@vstinnervstinnerMay 26, 2019
edited
Loading

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 ;-)).

@vstinner
Copy link
MemberAuthor

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

@pablogsal
Copy link
Member

pablogsal commentedMay 26, 2019
edited
Loading

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

Yup, I'm happy with it :)

@vstinnervstinner merged commit71c52e3 intopython:masterMay 27, 2019
@vstinnervstinner deleted the unraisable_msg branchMay 27, 2019 06:57
DinoV pushed a commit to DinoV/cpython that referenced this pull requestJan 14, 2020
* sys.unraisablehook: add 'err_msg' field to UnraisableHookArgs.* Use _PyErr_WriteUnraisableMsg() in _ctypes _DictRemover_call()  and gc delete_garbage().
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@serhiy-storchakaserhiy-storchakaserhiy-storchaka left review comments

@pablogsalpablogsalpablogsal left review comments

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@vstinner@pablogsal@serhiy-storchaka@the-knights-who-say-ni@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp