[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

STINNER Victor report at bugs.python.org
Wed May 22 11:30:01 EDT 2019


STINNER Victor <vstinner at redhat.com> added the comment:

I merged my PR #13187, so I reject PR #13175.

In the python-dev thread, there is no consensus in favor of -X abortunraisable option. The few people who pronounce them on this option were more against it.
https://mail.python.org/pipermail/python-dev/2019-May/157436.html

At least, you can now very easily reimplement it in a few line of pure Python using the new sys.unraisablehook! For example, add this code to Lib/site.py:
---
if 'abortunraisable' in sys._xoptions:
    import signal
    def abort_hook(unraisable,
                   # keep a reference to continue to work
                   # during Python shutdown
                   raise_signal=signal.raise_signal,
                   SIGABRT=signal.SIGABRT):
        raise_signal(SIGABRT)
    sys.unraisablehook = abort_hook
---

Example with attached gc_callback.py:
---
$ ./python -X dev gc_callback.py 
Exception ignored in: <function wr_callback at 0x7fa973faf870>
Traceback (most recent call last):
  File "gc_callback.py", line 7, in wr_callback
    raise ValueError(42)
ValueError: 42

$ ./python -X abortunraisable gc_callback.py 
Aborted (core dumped)

$ ./python -X abortunraisable -X faulthandler gc_callback.py 
Fatal Python error: Aborted

Current thread 0x00007fed6edc7740 (most recent call first):
  File "/home/vstinner/prog/python/master/Lib/site.py", line 649 in abort_hook
  File "gc_callback.py", line 11 in <module>
Aborted (core dumped)
---

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36829>
_______________________________________


More information about the Python-bugs-list mailing list