← 输入框|bugs.python.org|刷新

➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

作者 vstinner
收信人 ZackerySpytz, graingert, matrixise, serhiy.storchaka, vstinner
日期 2019-05-22.21:45:57
SpamBayes Score -1.0
Marked as misclassified 是
Message-id <1558561557.16.0.219529956893.issue36829@roundup.psfhosted.org>
In-reply-to
内容
In PR 13490, Thomas Grainger proposed a cool context manager:

@contextlib.contextmanager
def throw_unraisable_exceptions():
    unraisable = None
    old_hook = sys.unraisablehook

    def hook(exc):
        nonlocal unraisable
        unraisable = exc

    sys.unraisablehook = hook
    try:
        yield
        if unraisable is not None:
            raise unraisable
    finally:
        unraisable = None
        sys.unraisablehook = old_hook

It allows to raise an unraisable exception :-D Example:

try:
    with support.throw_unraisable_exceptions():
        ...
except Exception as e:
    ... # the exception is now here

I don't need such context manager right now, but I like the fact that it becomes possible to write such context manager :-)
历史
日期 用户 动作 参数
2019-05-22 21:45:57vstinner修改recipients: + vstinner, serhiy.storchaka, graingert, matrixise, ZackerySpytz
2019-05-22 21:45:57vstinner修改messageid: <1558561557.16.0.219529956893.issue36829@roundup.psfhosted.org>
2019-05-22 21:45:57vstinner链接issue36829 messages
2019-05-22 21:45:57vstinner创建