◐ Shell
reader mode source ↗
Skip to content

bpo-36829: Add _PyErr_WriteUnraisableMsg()#13488

Merged
vstinner merged 1 commit into
python:masterfrom
vstinner:unraisable_msg
May 27, 2019
Merged

bpo-36829: Add _PyErr_WriteUnraisableMsg()#13488
vstinner merged 1 commit into
python:masterfrom
vstinner:unraisable_msg

Conversation

@vstinner

@vstinner vstinner commented May 22, 2019

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

@vstinner

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

@vstinner

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

@vstinner

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Member Author

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

@vstinner

Copy link
Copy Markdown
Member Author

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

@pablogsal

pablogsal commented May 26, 2019

Copy link
Copy Markdown
Member

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

Yup, I'm happy with it :)

@vstinner vstinner merged commit 71c52e3 into python:master May 27, 2019
@bedevere-bot bedevere-bot removed the 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
* sys.unraisablehook: add 'err_msg' field to UnraisableHookArgs.
* Use _PyErr_WriteUnraisableMsg() in _ctypes _DictRemover_call()
  and gc delete_garbage().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants